私は検索を通してこれに対する答えをどこにも見つけることができないようです...
vbaを使用してWebページのリストを反復処理し、Excelでデータを使用しようとしています。
Webページへのアクセスは問題ありません。正しいdivを見つけることは問題ありませんが、リストを反復処理する方法が見つかりません。
私が試しているのは:
Sub getdata()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = False
ie.navigate "http://www.springfieldeducationalfurniture.co.uk/products/60-Chair-Trolley/11116/"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Attempting connection ..."
DoEvents Loop
Set html = ie.document
Set ie = Nothing
Application.StatusBar = ""
Dim content Set content = html.getElementsByClassName("tabs__content")
For Each bullet In content
'tried this
IHtml = bullet.innerHTML'this gives the whole div not sure how to convert to a string
'and this but get "Run-time error '438': Object doesn't support this property or method"
IHtml = bullet.getElementsByTagName("li")
Next
End Sub
彼らは次のようである私は後に、私はを反復処理したいアムHTML<ul>
内<div class="tabs__content">
とIEコンテンツを割り当てること(私は、リストからデータを読み取ると、残りは簡単です)Excelのセルに「組み立て簡単な自己が必要」:
<div class="tabs">
<div class="container">
<ul class="tabs__nav">
<li class="is-active background-grey-lighter">
<a href="#">Description</a>
</li>
<li class="background-grey-light">
<a href="#">Delivery</a>
</li>
</ul>
</div>
<div class="tabs__tab tabs__tab--product-info is-active">
<div class="tabs__title">
<a href="#">Information</a>
</div>
<div class="tabs__content">
<div class="container">
<p>
60 Chair Trolley</p>
<ul>
<li>
Requires simple self assembly</li>
<li>
Non marking wheels </li>
<li>
Heavy duty lockable castors</li>
<li>
Black frame</li>
<li>
Vertical / hanging chair storage</li>
<li>
Does not fit through a single doorway</li>
<li>
Fits through double doors when fully loaded</li>
<li>
Dimensions: W780 x L1770 x H1340mm</li>
</ul>
<p>
Code: Y16527<br />
</p>
</div>
</div>
</div>
<div class="tabs__tab tabs__tab--product-info ">
<div class="tabs__title">
<a href="#">Delivery</a>
</div>
<div class="tabs__content">
<div class="container">
<p>
Please <a href="/contact"><span style="color: rgb(0, 0, 255);">contact us</span></a> for delivery information.</p>
</div>
</div>
</div>
</div>
そして、これはあなたが言及したクラスを対象としています。HTMLオブジェクトライブラリとMicrosoftXML(ご使用のバージョン)への参照が必要です
Option Explicit
Sub Getinfo2()
Dim http As New XMLHTTP60
Dim html As New HTMLDocument
With http
.Open "GET", "http://www.springfieldeducationalfurniture.co.uk/products/60-Chair-Trolley/11116/", False
.send
html.body.innerHTML = .responseText
End With
Dim posts As MSHTML.IHTMLElementCollection
Dim post As MSHTML.IHTMLElement
Set posts = html.getElementsByClassName("tabs__content")(0).getElementsByTagName("li")
For Each post In posts
Debug.Print post.innerHTML
Next post
End Sub
出力:
これにより、すべてのli要素のhtmlが取得されます
Option Explicit
Sub Getinfo2()
Dim http As New XMLHTTP60
Dim html As New HTMLDocument
With http
.Open "GET", "http://www.springfieldeducationalfurniture.co.uk/products/60-Chair-Trolley/11116/", False
.send
html.body.innerHTML = .responseText
End With
Dim posts As MSHTML.IHTMLElementCollection
Dim post As MSHTML.IHTMLElement
Set posts = html.getElementsByTagName("li")
For Each post In posts
Debug.Print post.innerHTML
Next post
End Sub
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加