2015-09-10 39 views
-1

我想在tumblr中更改我的网址,但我已将硬编码链接指向我的博客。我没有进入超过1000个帖子并手动更新链接,我被告知可以自动化。我需要它:编辑并替换tumblr文章中的部分网址

  1. 访问博客的页面
  2. 检查后
  3. 如果存在的超链接文本中的旧网址,单击编辑,编辑后的内容
  4. 点击URL文本区域,在弹出的
  5. 单击编辑那会出现
  6. 在新的URL的弹出替换URL中的一部分(例如:如果我们开始与http://old.tumblr.com/tagged,我们会再想要http://new.tumblr.com/tagged
  7. 单击完成,在弹出的关闭并保存网址变更
  8. 保存更改后
  9. 继续检查页面
  10. 如果没有发生更多的情况下,在接下来的文章中,继续到下一个页面
  11. 重复,直到到达最后一页

所以我相信我理解所需的逻辑/步骤,但我的缺陷是能够执行它们。什么才是最好的语言或方法去实施呢?直接的首选,因为我是一个完整的编码新手。 Python被提到了我。 Autohotkey也许,以及?

我很抱歉,如果这不是正确的地方问。

目前我在旧URL的页面上有一个重定向。

<title>Redirect</title> 
 
<script>location.replace('http://new.tumblr.com' + location.pathname);</script> 
 
<noscript> 
 
<h1>This blog has moved to <a href="http://new.tumblr.com/">New Blog</a>.</h1> 
 
<p>If you&rsquo;re reading this, you have JavaScript turned off and therefore can&rsquo;t be redirected automatically. Replace &ldquo;{BlogURL}&rdquo; with &ldquo;http://{text:New Tumblr URL}.tumblr.com/&rdquo; in your browser&rsquo;s address bar to get to your destination.</p> 
 
</noscript>

+0

你可以告诉你试过吗? – mikedidthis

+0

现在,我在旧网址的页面上重定向了位置 – ash

+0

@mikedidthis -I在上述帖子中添加了重定向代码。我猜,它完成了工作。 – ash

回答

1

井AutoHotkey的我会使用IE的COM自动化来完成这项工作,这将会是最可靠的。

Com Object Reference

编辑:

使用浏览器的自动化方法坦率地编辑HTML只是去对此非常低效的方式。如果您有权访问该网站,则可能直接访问上传HTML文件。如果是这种情况,下面的代码应该为您提供足够的有关如何编辑页面中包含的链接的详细信息。

下面的代码是简化你将要做的事情。只是为了熟悉这个过程。

html = 
(
<html> 
<body> 
<a href="http://old.tumblr.com/tagged1"/>this old link</a> 
<a href="http://old.tumblr.com/tagged2"/>this old link two</a> 
<a href="http://old.tumblr.com/tagged3"/>this old link three</a> 
<a href="http://new.tumblr.com/tagged3"/>this new link</a> 
</body> 
</html> 
) 

pwb := ComObjCreate("HTMLfile"), pwb.Write(html) 
Links := pwb.Links 
Loop % Links.Length ; check each link 
     If ((RelatedLink := Links[A_Index-1].href) != "" && (Links[A_Index-1].href ~= "http://old.")) { ; if the link is not blank 
       Links[A_Index-1].href := StrReplace(Links[A_Index-1].href, "http://old.", "http://new.") 
      } 

html := pwb.documentElement.innerHTML 
MsgBox % html 

这是我怎么会去把它应用到了一堆网站:

SetBatchLines -1 
fileName := A_ScriptDir . "\myfile.txt" 

MyListOfWebPages = ; add all your blog page urls here 
(
http://myblogpageone.html 
http://myblogpagetwo.html 
http://myblogpagethree.html 
http://myblogpagefour.html 
) 

For Each, Line in StrSplit(MyListOfWebPages, "`n", "`r") { 
      FileAppend, % GrabWebPage(Line), % A_scriptDir "\htmlfile" A_index ".html" 
} 

GrabWebPage(Webpage) { 
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") 
;Change below to your URL 
whr.Open("GET", Webpage, true) 
whr.Send() 
whr.WaitForResponse() 
pwb := ComObjCreate("HTMLfile"), pwb.Write(whr.ResponseText) 

Links := pwb.Links ; collection of hyperlinks on the page 
    Loop % Links.Length ; check each link 
     If ((RelatedLink := Links[A_Index-1].href) != "" && (Links[A_Index-1].href ~= "http://old.")) { ; if the link is not blank 
       Links[A_Index-1].href := StrReplace(Links[A_Index-1].href, "http://old.", "http://new.") 
      } 
    Return pwb.documentElement.innerHTML 
} 
+0

我会检查。谢谢!已添加代码 – ash

+0

。 – errorseven