Gary
Gary

Reputation: 209

VBA: It only shows ID at Ispect Element

I'm a newbie at VBA programming, and I use it to build macro a in excel. Here is this webpage: http://www.eppraisal.com/home-values/property/14032-s-atlantic-ave-riverdale-il-60827-59143864/

I want to extract the value of $52,920 on the right upper corner. When I select the Inspect Element, this is the following:

<p id="eppraisalval">$52,920</p>

I checked the Page Source, but I couldn't find it. The closest thing I found:

<span id="eppraisal_val" class="valuation-estimates-price ajaxload" data-url="/home-values/property_lookup_eppraisal?a=14032%20S%20Atlantic%20Ave&z=60827&propid=59143864">loading...</span>

I tried the get getElementById("eppraisal_val") and getElementById("eppraisalval"), but none of those worked. How can I address my code to get that element?

Here is more from the inspect element window, aroun that code:

<span id="eppraisal_val" class="valuation-estimates-price ajaxload" data-url="/home-values/property_lookup_eppraisal?a=14032%20S%20Atlantic%20Ave&amp;z=60827&amp;propid=59143864"><p id="eppraisalval">$52,920</p><p class="main-page-description-small valuation_details" style="display:none;margin-top:5px">Low: $44,982 <br>High: $60,858</p></span>

Here is the shorter version of code I tried:

Sub macroID()
 On Error Resume Next
 Dim ie As Object
 Set ie = CreateObject("internetexplorer.application")
 Dim doc As HTMLDocument

 Dim valuation As String
 Dim val1 As String, val2 As String

 Set doc = ie.Document
 ie.Visible = True
 ie.navigate "http://www.eppraisal.com/home-values/property/14032-s-atlantic-ave-riverdale-il-60827-59143864/"
 Do
     DoEvents
     Loop Until ie.readyState = READYSTATE_COMPLETE

 Set doc = ie.Document
 valuation = doc.getElementById("eppraisalval")
 Cells(1, 4).Value = valuation
 Application.Wait (Now + TimeValue("0:00:03"))


End Sub

Upvotes: 0

Views: 90

Answers (1)

Jordan
Jordan

Reputation: 4514

The issue with scraping from that URL is that there is a verification page before hand which requires you to confirm you "are not a robot" which makes it hard to scrape anything from it.

If you manually do this first it may save this in your cache and then allow you to run macros freely to scrape the website however you'd have to try this out.

In the meantime, the only issue I could see with your code is that you haven't included .innertext after .getElementById("eppraisalval"). The valuation line should look like this:

valuation = doc.getElementById("eppraisalval").innerText

Upvotes: 1

Related Questions