Type error between collection and element

evd46

New Member
Joined
Apr 8, 2013
Messages
2
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&amp;idcat=48640 ">
<div class="tile_content">
<span class="tile_title">Ap&#233;ritif</span>
</div>
<div class="txt-primary">
<span>52 recettes</span>
</div>
</a>
</article>
</div>
</section>
</div>
</div>

I need to access "48640", "Ap&#233;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?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top