我当前有以下代码,它不起作用,给我一个对象变量或没有设置块变量。
Set doc = IE.document
Dim sDD4 As String
sDD4 = Trim(doc.getElementById("productInfoContainter").getElementsByTagName("span")(0).innerText)
Sheet1.Cells(i, 8) = sDD4
我试图从以下内容中提取的html:
<div id="productInfoContainter" style="display: block;">
<table width="100%" style="display: none;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top">
<div style="margin: 5px;">
<span class="notranslate" onmouseover="_tipon(this)" onmouseout="_tipoff()">
<span class="google-src-text" style="text-align: left; direction: ltr;">
<b>text i need 1</b>
</span>
<b>text i need 2</b>
</span>
</div>
</td>
</tr>
<tr>
<td valign="top">
<div style="margin: 10px 10px 20px;" itemprop="description"></div>
</td>
</tr>
</tbody>
</table>
我也尝试过getElementbyClassName(&#34; google-src-text&#34;)(0).innerText
出现了同样的错误。
基本上我正试图在谷歌翻译网站翻译取出翻译文本的主体
任何帮助表示赞赏
答案 0 :(得分:0)
我期望的代码是这样的
Sub WebNavigate()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "www.YourWebsite.com/Links"
With objIE
.Visible = True
.navigate WebSite
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set Element = .document.getElementById("productInfoContainter")
Sheet1.Cells(i, 8) = Element.innertext
End With
End Sub