Error 91 while scraping web

evd46

New Member
Joined
Apr 8, 2013
Messages
2
With this vba-code :
If Not DishesDoc.getElementById("ContentPlaceHolder_LblRecetteTempsPrepa") Is Nothing Then
Failure = DishesDoc.getElementById("ContentPlaceHolder_LblRecetteTempsPrepa").innerText 'Failure being declared as an object
End If

I want to scrape data from this piece of HTML-code :
<ul class="borderSection_toolbar icon-prepa">
<li id="ContentPlaceHolder_trPrepa">Préparation
<span id="ContentPlaceHolder_LblRecetteTempsPrepa">15 min</span>
</li>
<li class="hide-for-small-only">
<button type="button" class="button dark border icon-step" data-stepper></button>
</li>
</ul>

Yet it produces a #91-error.
The code following this test gives the same error :
Debug.Print "Temps de préparation : " & Left(DishesDoc.getElementById("ContentPlaceHolder_LblRecetteTempsPrepa").innerText, Len(DishesDoc.getElementById("ContentPlaceHolder_LblRecetteTempsPrepa").innerText) - 4) & " minutes".

As this latter code works fine for most of the similar yet not identically coded pages, I want to avoid the code to crash on the differently coded pages.
PS: I tried to use the on error resume next and the on error goto errorhandler, but also these do not work.

How can I best solve these problems?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
How can I best solve these problems?
Hi, start with a complete elaboration like any Excel forum expects for ! In order there is nothing to guess …​
You can try some Debug.Print codelines on each web element to find out where the error raises.​
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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