Excelマクロを使用してGoogle検索ページを開く必要があります。Excel で検索パラメータを指定すると、Google 検索ページを正常に開くことができます。ただし、私のタスクは、最初に返された検索結果ページを開いて、そのページでデータ抽出を行うことです。以下のコードを使用しました。
「Sachin Tendulkar wiki」を検索した場合、検索結果の最初のページを開くことができるはずです。これまでの私のコードは以下の通りです。
Dim ie As InternetExplorer
Dim RegEx As RegExp, RegMatch As MatchCollection
Dim MyStr As String
Dim pDisp As Object
Set ie = New InternetExplorer
Set RegEx = New RegExp
Dim iedoc As Object
'Search google for "something"
ie.Navigate "http://www.google.com.au/search?hl=en&q=sachin+tendulkar+wiki&meta="
'Loop unitl ie page is fully loaded
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
MyStr = ie.Document.body.innertext
Set RegMatch = RegEx.Execute(MyStr)
'If a match to our RegExp searchstring is found then launch this page
If RegMatch.Count > 0 Then
ie.Navigate RegMatch(0)
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
MsgBox "Loaded"
'show internet explorer
ie.Visible = True
'Private Sub ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set iedoc = ie.Application.Document
'iedoc.getElementById("divid").Value = "poS0"
'MsgBox iedoc
'ie.Navigate iedoc.getelementsbytagname("ol")(0).Children(0).getelementsbytagname("a")(0).href
ie.Navigate iedoc.getelementsbyclassname("divid")("poS0").href
Else
MsgBox "No linkedin profile found"
End If
Set RegEx = Nothing
Set ie = Nothing
Google 検索ページでページのソースを表示しました。最初の検索結果の ID である特定の div id = "pos0" があります。IE を div id = "pos0" のページにナビゲートする必要があります。VBAでこれを達成することはできません。誰かが私を助けてくれませんか?
よろしくお願いします、 ラメッシュ