运行我的vba脚本我可以看到它无法到达目标页面,我想从中提取不同的名称。很明显,我已经搞乱了我的代码,但无法找到答案。希望有人能帮我找出我犯的错误。谢谢。下面是代码:使用GET请求无法到达目标页面
Sub Getmethod()
Dim http As New MSXML2.ServerXMLHTTP, html As New HTMLDocument
Dim topics, topic, ele As Object
Dim StrData As String
StrData = "what=Plumbers/where=All+States"
With http
.Open "GET", "http://www.yellowpages.co.za/search/" & StrData, False
.setRequestHeader "Content-Type", "text/xml"
.send
html.body.innerHTML = http.responseText
End With
Set topics = html.getElementsByClassName("resultName")
For Each topic In topics
Set ele = topic.getElementsByTagName("a")(0)
x = x + 1
Cells(x, 1) = ele.innerText
Next topic
End Sub
这里的形式元素:
<form action="/search/" class="searchForm" id="searchForm" autocomplete="off">
<div id="whatDiv">
<label class="searchLabel whatLabel" data-icon="">
<input type="search" id="whatField" name="what" class="searchField whatField" placeholder="Search for companies and services" autocomplete="off" tabindex="1">
</label>
</div>
<input type="submit" value="GO" class="searchBtn" tabindex="3" id="searchBtn">
<label class="searchLabel whereLabel" data-icon="">
<input type="search" id="whereField" name="where" class="searchField whereField" placeholder="Location" autocomplete="off" tabindex="2">
</label>
</form>
您确定使用搜索参数的网址吗?如果我把这个URL放在浏览器中,它不会返回任何东西。当我尝试在'斗篷镇'中搜索'水管工'时,URL如下所示:http://www.yellowpages.co.za/Search/plumbers/cape + town,+ western + cape/1'。所以也许你的网址不正确?你是否首先手动尝试这个URL? – dee
谢谢先生,为您的回应。不,我没有手动尝试.. – SIM
那么,你可能应该先尝试在浏览器中看到,如果URL是正确的,它实际上返回的东西。 – dee