Hev
Hev

Reputation: 75

How to scrape online data from within a span tag

I am trying to get the value R1200 as defined by the "one Way drop off surcharge" description.I have tried using various methods of getting the element but have not been able to get the information. The idea is, I want to fetch the 1200 value and paste it into a cell in excel. I am new to both vba and html.

I have already managed to get the scraping tool to navigate to the specific webpage in question by clicking the relevant inputs, below is the sample code I have tried to get the value.

This is the HTML where the value resides:

<div class="itinerary-column">
<div class="optional-extras">
<h4>
Price Summary
</h4>
<ul class="clearfix extras">

<li>
Document admin fee<span>R 99.00</span>
</li>
<li>
Vehicle Rental <span>R 1575.00</span>
</li>
<li>
<!--This is part of the temporary solution to show the oneway surcharge-->
One Way Drop Off Surcharge<span>R 1200.00</span>
</li>
</ul>
</div>
<div class="total-price clearfix">
Total

<span>
R
<span class="value">
2874.00
</span>
</span>
</div>
<div class="deposit">
<div class="clearfix">
<div class="deposit-req">
Deposit required
<span>(Not included in total)</span>
</div>
<div class="value">
R <span>4170.20</span>
</div>
</div>
</div>
<div class="excess-message">
Rate incl 200 KMS free per day.Extra @ ZAR2.12 p k
</div>

</div>

This is the code I have tried to get the value:

'Cells(r, 3).Value = appIE.document.getElementsByClassName("optional-extras").innerHTML
'Cells(r, 2).Value = appIE.document.getElementsByClassName("optional-extras").innerText
Cells(r, 6).Value = appIE.document.getElementsByClassName("optional-extras").innerHTML
Cells(r, 6).Value = appIE.document.getElementsByClassName("clearfix extras").innerHTML
'Cells(r, 4).Value = appIE.document.getElementsByClassName("clearfix extras").innerText
'Cells(r, 5).Value = appIE.document.getElementsByClassName("clearfix extras").innerHTML
'Cells(r, 6).Value = appIE.document.getElementsByTagName("ul").Item(25).innerText   'yields something

Upvotes: 2

Views: 725

Answers (2)

QHarr
QHarr

Reputation: 84465

How many elements have the compound classes of clearfix extras? As a general selector the following is correct: .clearfix.extras li:nth-of-type(3) span

Used as follows:

Debug.Print appIE.document.querySelector(".clearfix.extras li:nth-of-type(3) span").innerText

However, if your item is not in the first element with that compound class then the css selector will need expanding to account for that

OP says 3 needs to be 2 for case in hand

Upvotes: 0

Netlog
Netlog

Reputation: 135

if you want scrape inside of a tag from a remote (or local!) web page just use below free DOM parser
PHP Simple HTML DOM Parser
there is a good manual and samples, its so simple to use ...

Upvotes: 0

Related Questions