使用Google翻译进行网页抓取不起作用

时间:2020-06-11 09:15:09

标签: html vba web-scraping

我很难理解为什么在下面的代码中第一个URL返回页面,而第二个URL不返回页面。

    Sub Test()
    Dim URL, TRanslatedText As String
    Dim HTTPObject As Object

    ' first URL (works)        
    URL = "https://translate.google.com/m?hl=auto&sl=auto&tl=en&ie=UTF-8&prev=_m&q=No entiendo"

    ' second URL (does not work)        
    'URL = "https://translate.google.com/#view=home&op=translate&sl=auto&tl=en&text=No%20entiendo"

    Set HTTPObject = CreateObject("MSXML2.XMLHTTP")
    HTTPObject.Open "GET", URL, False
    HTTPObject.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    HTTPObject.send

    Cells(1, 1) = HTTPObject.responseText
    End Sub

为什么第二个URL不起作用...?

0 个答案:

没有答案