bounty将在5天后过期。回答此问题可获得+50的声誉奖励。user3618585正在寻找来自声誉良好来源的答案。
我在阅读下面代码的描述和价格时遇到问题。此代码从迈阿密Craigslist自动页面打开前4页,并将描述和价格读取到Excel。此代码成功打开前4页:
Sub fortesting()
Dim link As HTMLLinkElement
Dim blog As HTMLLinkElement
Dim price As HTMLLinkElement
Dim IE As Object
Dim html As HTMLDocument
Dim URL As String
Dim URLParameter As String
Dim page As Long, counter As Long
'Dim http As Object
Dim links As Object
Dim blogpost As Object
Dim priceonly As Object
Dim Results As Object
Dim StartCell As Range
Dim increment As Integer
Dim htmlele1 As HTMLLinkElement
Dim ss As Integer
Dim ee As Integer
Dim Index As Integer
Dim k As Integer
Dim q As Integer
q = Format(k, "0")
' This is the first cell that a blog post hyperlink is created in
Set StartCell = Range("A1")
URL = "https://miami.craigslist.org/search/cta"
Set IE = CreateObject("InternetExplorer.Application")
Application.ScreenUpdating = True
' CHnage this to False if you want to hide IE
IE.Visible = True
counter = 0
page = 0
'Set the number of pages of the website to go through in the browser
For page = 0 To 4 Step 1 'increment by 1 - total 4 pages
Debug.Print page
If page >= 0 Then URLParameter = "#search=1~list~" & page & "~0"
IE.navigate URL & URLParameter
'Wait for the browser to load the page
Do Until IE.readyState = 4
DoEvents
Loop
Set html = IE.document
Set links = html.getElementsByTagName("h3")
Index = 0
For Each link In links
If InStr(LCase(link.outerHTML), "result-heading") Then
Set blogpost = link.getElementsByTagName("title-blob")
Set priceonly = link.getElementsByClassName("priceinfo")
Set Results = html.getElementsByClassName("result-row")
For Each blog In blogpost
StartCell.Offset(counter, 0).Hyperlinks.Add _
Anchor:=StartCell.Offset(counter, 0), Address:=blog, _
TextToDisplay:=link.innerText
StartCell.Offset(counter, 1).Value =
Results(Index).getElementsByTagName("span")(0).innerText
Index = Index + 1
Next blog
counter = counter + 1
End If
Next link
Next page
IE.Quit
Set IE = Nothing
Columns("B:B").Select
Selection.NumberFormat = "$#,##0.00"
Columns("D:D").Select
Selection.NumberFormat = "m/d/yyyy;@"
End Sub
任何帮助都是高度赞赏的。我只需要阅读说明和价格。例如:范围(“A1”)= 2008款凯迪拉克凯雷德范围(“B1”)= 8,500美元
1条答案
按热度按时间eqzww0vc1#
如果你把这个函数放在一个模块中,它可以被调用来下载任何html(或任何其他来自网络的文件)-并在你的计算机上的“ToFile”中返回结果。
如果我对我们的URL进行测试,它会接受HTML,但不会接受js(Java Script)的结果,js会向网页返回InnerHtml元素。
末端子组件