我可以从已知的ulr中提取数据,但我可以使用excel浏览网站吗。
例如,excel可以进行谷歌搜索并将结果放在电子表格中。或者浏览框内网站。
此代码从网站提取数据。
With ActiveSheet.QueryTables.Add(Connection:= _
PUT_URL_HERE, _
Destination:=Range("A1"))
.Name = "I need serious help"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
答案 0 :(得分:5)
嘿所以我想出了这个,并认为我会发帖以防万一有人遇到类似的问题。
Sub googlesearch()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "www.google.com"
With objIE
.Visible = True
.navigate WebSite
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set Element = .document.getElementsByName("q")
Element.Item(0).Value = "Hello world"
.document.forms(0).submit
'.quit
End With
End Sub
为了成功完成这项工作,你需要知道元素名称(你可以通过查看源代码或安装一个帮助你喜欢firebug的插件来实现),你也可以使用.getElementsByID(“someIDhere”)。< / p>
答案 1 :(得分:1)
我知道这有点晚了,但这是一个解决方案。你需要做界面来传递搜索词,如果需要,验证/编码等等。它需要你的PC上的Internet Explorer。它会为您提供原始HTML,您必须根据需要对其进行解析。
Function GoogleSearch(strSearchTerm As String) As String
Dim ie As Object
Dim sHTML As String
On Error GoTo ZERR
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = False
.navigate ("http://www.google.com/search?q=" & strSearchTerm)
Do Until .readystate = 4
DoEvents
Loop
sHTML = .document.Body.innerHTML
End With
Set ie = Nothing
GoogleSearch = sHTML
ZERR:
Set ie = Nothing
End Function