运行我的vba脚本我可以看到它无法到达我希望从中提取不同名称的目标页面。很明显,我在代码中已经搞砸了,但无法找到答案。希望有人能帮助我找出我犯错误的地方。谢谢。这是代码:
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>
答案 0 :(得分:0)
将StrData
的内容更改为"Plumbers/All+States"
。然后像这样返回数据:
Flinkdink Plumbers CC →
AD-Hoc Plumbers →
GANGA PLUMBERS →
BURGESS PLUMBING →
Burgess & Partners →
Drainmen →
Drainmen →
Anchor Electrical →
Cobra →
Bryanston Plumbing (Pty) Ltd →
Amazon →
A A A Plumbers →
A A A Plumbing →
A A A Plumbing →
Berea Plumbers →
Drain Blasters →
R C Bosman Plumbing →
R C Bosman Plumbing →
Currie Plumbers →
DRAIN GEYSER PLUMBING EXPERTS →