Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
希望使用excel vba从网站中提取文本_Excel_Vba_Web - Fatal编程技术网

希望使用excel vba从网站中提取文本

希望使用excel vba从网站中提取文本,excel,vba,web,Excel,Vba,Web,我当前有以下代码不工作,给我一个对象变量或块变量未设置 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" st

我当前有以下代码不工作,给我一个对象变量或块变量未设置

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>

文本我需要1
文本我需要2
我还尝试过getElementbyClassName(“谷歌src文本”)(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
子网站导航()
Set objIE=CreateObject(“InternetExplorer.Application”)
WebSite=“www.YourWebsite.com/Links”
与奥布杰
.Visible=True
.浏览网站
请稍等片刻。忙碌或。准备就绪状态4
多芬特
环
Set元素=.document.getElementById(“ProductInfoContainer”)
Sheet1.单元格(i,8)=Element.innertext
以
端接头

我打赌
ProductInfoContainer
是一个打字错误。前几行是代码的简化版本吗。因为我没有看到你打开网站?或者设置doc.navigate,我看到您正在根据标记从excel调用代码。您是否设置了使用Internet控件的引用?