Fork me on GitHub

VBA Scraping

Extract data from websites easily
Dim doc As New Scraping

doc.gotoPage "https://example.com/"
The text of the first <a> element

doc.css("a").index(0).text
<div id="bar">
  <p>Links:</p>
  <ul>
    <li><a>href="http://github.com">Github</a></li>
    <li><a>href="http://w3schools.com">w3schools</a></li>
    <li><a>href="http://youtube.com/">YouTube</a></li>
    <li><a>href="http://wikipedia.org">Wikipedia</a></li>
  </ul>
</div>
Download
Last update July 02, 2017
More examples
The text of an element with id

doc.id("nameId").text
<div><button id="nameId">Submit</button></div>
The <title> element

doc.css('title')
<html>
<head><title>My webpage</title></head>
<body>
<h1>Hello!</h1>
All <li> elements

doc.css("li")
<div id="bar">
  <p>Links:</p>
  <ul>
    <li><a>href="http://github.com">Github</a></li>
    <li><a>href="http://w3schools.com">w3schools</a></li>
    <li><a>href="http://youtube.com/">YouTube</a></li>
    <li><a>href="http://wikipedia.org">Wikipedia</a></li>
  </ul>
</div>
The url of the second <a> element

doc.css("a").index(1).attr("href")
<div id="bar">
  <p>Links:</p>
  <ul>
    <li><a>href="http://github.com">Github</a></li>
    <li><a>href="http://w3schools.com">w3schools</a></li>
    <li><a>href="http://youtube.com/">YouTube</a></li>
    <li><a>href="http://wikipedia.org">Wikipedia</a></li>
  </ul>
</div>