0

我正在做的是这样的:

  1. 加载 www.google.com
  2. 在输入框中输入内容以搜索 Google.com
  3. 然后在文本文件中检索 google 提供的链接。

我尝试了下面的脚本,但它没有返回 Google 提供的“链接”:

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = TRUE
ie.Navigate("https://www.google.co.in/#hl=en&output=search&sclient=psy-  ab&q=my+sa+fria&oq=my+sa+fria&gs_l=hp.3...136.425.0.1178.5.4.0.0.0.2.318.916.0j2j1j1.4.0.les%3B..0.0...1c.1.5.psy-ab.ILEhJPZdulQ&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.43148975,d.bmk&fp=aceecfc5e1faf854&biw=1366&bih=487")
Do until ie.ReadyState = 4
WScript.Sleep 50
Loop

set urls = ie.document.all.tags("a")
 For x = 0 to (urls.length)-1
 wscript.echo urls(x).innerHTML & " : " & urls(x).href
Next
wscript.echo "Number of URLs:", urls.length, vbNewline
4

1 回答 1

1

搜索结果位于<h3>标签中,因此您可以使用此信息将它们与页面上的其他链接区分开来。尝试这个:

searchUrl   = "http://www.google.co.in/search?q="
searchTerms = Array("my", "sa", "fria")

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate searchUrl & Join(searchTerms, "+")

Do Until ie.ReadyState = 4
  WScript.Sleep 50
Loop

Set results = ie.document.all.tags("h3")
For Each anchor In results.children.tags("a")
  WScript.Echo anchor.href
Next
WScript.Echo "Number of results:", results.Length, vbNewline
于 2013-03-04T23:18:53.773 回答