I try to collect three data from a a website, but encounter an error 13 = type incompatibility. What do I do wrong ?
Here is (part of) the website code:
<div id="liste-recettes-preferees" class="row">
<div class="small-12 columns">
<section id="profileCollections" class="aggregate">
<div class="tiles threecolumns">
<article id="listItemCat" class="tile book cookbook">
<a id="catLink" href="/communaute/ma_cuisine.aspx?Id=176522&idcat=48640 ">
<div class="tile_content">
<span class="tile_title">Apéritif</span>
</div>
<div class="txt-primary">
<span>52 recettes</span>
</div>
</a>
</article>
</div>
</section>
</div>
</div>
I need to access "48640", "Apéritif" and "52".
I developped therefore the following code (heavily truncated) :
Sub GrabRecepesHTML()
'DIMENSION VARIABLES
Dim Sourcewebsite As New SHDocVw.InternetExplorer 'Internet Explorer
Dim SourceDoc As MSHTML.HTMLDocument 'Sourcewebsite.document
Dim CatEle As MSHTML.HTMLDocument 'element of CatCol
Dim CatCol As MSHTML.IHTMLElementCollection 'collection of categories (like Apéritif, Entrée, ...)
Dim y As Integer 'simple counter in loop
Dim CatList() As Variant '1 = Name, 2 = URL of NextWebPage, 3 = number of pages to search through
'INITIALISE VARIABLES
Const MyFilePath = "D:\Docs\Recettes\"
Const SourceWebpage = "Nouveau compte CuisineAZ"
Call Open_Website(Sourcewebsite, SourceWebpage, True, TimeOut) 'third parameter = visibility : change to false 'Opens webpage perfectly
'Grab names of all categories (like "Apéritifs, Entrées, ...)
Set SourceDoc = Sourcewebsite.document
Set CatCol = SourceDoc.getElementById("liste-recettes-preferees").getElementsByClassName("tile book cookbook")
Debug.Print CatCol.Length, TypeName(CatCol) 'Results in "6" and "DispHTMLElementCollection"
ReDim CatList(CatCol.Length, 3)
For Each CatEle In CatCol 'Results in errorcode 13 = type incompatibility
For y = 1 To CatCol.Length
CatList(y, 1) = CatEle.textContent
CatList(y, 2) = "Nouveau compte CuisineAZ" & Right(CatEle.href, 5)
CatList(y, 3) = CatEle.getElementsByclass("txt-primary")(0).innerText
Debug.Print y, CatList(y, 1), CatList(y, 2), CatList(y, 3)
Next y
Next CatEle
End Sub
What is wrong ? How should I access these three data?
Here is (part of) the website code:
<div id="liste-recettes-preferees" class="row">
<div class="small-12 columns">
<section id="profileCollections" class="aggregate">
<div class="tiles threecolumns">
<article id="listItemCat" class="tile book cookbook">
<a id="catLink" href="/communaute/ma_cuisine.aspx?Id=176522&idcat=48640 ">
<div class="tile_content">
<span class="tile_title">Apéritif</span>
</div>
<div class="txt-primary">
<span>52 recettes</span>
</div>
</a>
</article>
</div>
</section>
</div>
</div>
I need to access "48640", "Apéritif" and "52".
I developped therefore the following code (heavily truncated) :
Sub GrabRecepesHTML()
'DIMENSION VARIABLES
Dim Sourcewebsite As New SHDocVw.InternetExplorer 'Internet Explorer
Dim SourceDoc As MSHTML.HTMLDocument 'Sourcewebsite.document
Dim CatEle As MSHTML.HTMLDocument 'element of CatCol
Dim CatCol As MSHTML.IHTMLElementCollection 'collection of categories (like Apéritif, Entrée, ...)
Dim y As Integer 'simple counter in loop
Dim CatList() As Variant '1 = Name, 2 = URL of NextWebPage, 3 = number of pages to search through
'INITIALISE VARIABLES
Const MyFilePath = "D:\Docs\Recettes\"
Const SourceWebpage = "Nouveau compte CuisineAZ"
Call Open_Website(Sourcewebsite, SourceWebpage, True, TimeOut) 'third parameter = visibility : change to false 'Opens webpage perfectly
'Grab names of all categories (like "Apéritifs, Entrées, ...)
Set SourceDoc = Sourcewebsite.document
Set CatCol = SourceDoc.getElementById("liste-recettes-preferees").getElementsByClassName("tile book cookbook")
Debug.Print CatCol.Length, TypeName(CatCol) 'Results in "6" and "DispHTMLElementCollection"
ReDim CatList(CatCol.Length, 3)
For Each CatEle In CatCol 'Results in errorcode 13 = type incompatibility
For y = 1 To CatCol.Length
CatList(y, 1) = CatEle.textContent
CatList(y, 2) = "Nouveau compte CuisineAZ" & Right(CatEle.href, 5)
CatList(y, 3) = CatEle.getElementsByclass("txt-primary")(0).innerText
Debug.Print y, CatList(y, 1), CatList(y, 2), CatList(y, 3)
Next y
Next CatEle
End Sub
What is wrong ? How should I access these three data?