VBA for Web Scraping help

epactheactor

New Member
Joined
Sep 9, 2015
Messages
38
Hello! I am trying to build a simple macro for a friend to make his life easier. It is to go to a web site and pull data from a certain section which will be pasted in Excel. I thought it would be a simple getElementByID or Class Name like I've done before, but I have not had any luck. Would love any suggestions or helpful hints. I'm putting a snippet of the HTML I'm trying to pull from below, where the sections that scream "I NEED THIS SECTION" are what I'm after. At first I tried to pull from ID "PIr11" but that gave me table header information. Then I tried by class name of "ssTableHeader" but got the same result. Also put a snippet of the VBA that I'm using way at the bottom. Thank you.

HTML:
<th class="ssTableHeaderLabel">Location:</th><td style="padding-left:10px"><b>Big Time</b></td></tr><tr><th class="ssTableHeaderLabel">Officer:</th><td style="padding-left:10px"><b>Doe, John</b></td></tr></table></td></tr></table></td></tr></table><table cellpadding="0" cellspacing="0" width="100%" border="0" style="table-layout: fixed" <col width="10%" /><col width="30%" /><col width="10%" /><col width="30%" /><col width="20%" /><caption><div class="ssDetailSectionTitle">Gen Information</div></caption><tr><td colspan="4"></td><th class="ssTableHeader" id="PIc5">Leader</th></tr><tr><th class="ssTableHeader" valign="top" rowspan="2" id="PIr01">Blocker</th><th class="ssTableHeader" valign="top" id="PIr11">Jane, Doe</th><td rowspan="2"></td><td rowspan="2" valign="top" headers="&#xD;&#xA;              PIr01 &#xD;&#xA;              PIr11">Dancer<br />
                      DOB: 1/1/1911<br />Good Dancer</td><td rowspan="2" valign="top" headers="&#xD;&#xA;              PIr01 &#xD;&#xA;              PIr11 &#xD;&#xA;              PIc5&#xD;&#xA;            "></td></tr><tr><td valign="top" headers="&#xD;&#xA;              PIr01 &#xD;&#xA;              PIr11">&nbsp;&nbsp;4327 AVE R <br />&nbsp;&nbsp;HOUSTON, TX 77777<br /></td></tr><tr height="25"><td colspan="5">&nbsp;</td></tr><tr><th class="ssTableHeader" valign="top" rowspan="2" id="PIr02">State</th><th class="ssTableHeader" valign="top" id="PIr12">The State</th><td rowspan="2"></td><td rowspan="2" valign="top" headers="&#xD;&#xA;              PIr02 &#xD;&#xA;              PIr12"> </td><td rowspan="2" valign="top" headers="&#xD;&#xA;              PIr02 &#xD;&#xA;              PIr12 &#xD;&#xA;              PIc5&#xD;&#xA;            "></td></tr><tr><td valign="top" headers="&#xD;&#xA;              PIr02 &#xD;&#xA;              PIr12">&nbsp;&nbsp;I NEED THIS SECTION<br />&nbsp;&nbsp;I NEED THIS SECTION<br /></td></tr></table>

VBA Code:
[CODE=vba]
[CODE=vba]URLa = Range("A3").Hyperlinks(1).Address

browser.navigate (URLa)

Set page = browser.document

Set otherElement = page.getElementsByClassName("ssTableHeader")

x = 1
num = 1
For Each ele In otherElement

    Cells(x, 10).Value = otherElement.Item(num).innerText
    x = x + 1
    num = num + 1
Next
[/CODE]
[/CODE]
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,102
Messages
6,123,097
Members
449,096
Latest member
provoking

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