Search code examples
htmlvbaweb-scrapingmailto

How to scrape mailto from following page using VBA


i am trying to scrape mailto (href) from a html file, but i am unable to "hit" it.

Any advice is welcome.

       <div class="exhibitor-contact">
            <div class="col">
                <h3>
                whatever           </h3>
      <p>
                    MLW <br />            whatever<br />            75008             Paris              - France          </p>
      <p>
                    <a class='inverse-a-span' href='#tel' id='tel' onclick="return xt_click(this,'C', xtn2, xtpage.replace(/\w*$/, 'exhibitor::tel').replace(/^Exhibitors::/, ''), 'A')">Show Phone Number</a><span style='display:none;'>whatever</span><br />                        <a href='mailto:[email protected]' onclick="return xt_click(this,'C',xtn2, xtpage.replace(/\w*$/, 'exhibitor::email').replace(/^Exhibitors::/, ''), 'A')">Send an Email</a><br />                      </p>
    </div>
          </div>



</section>

Code:

Set my_data = IE.Document.getElementsByClassName("anyclass") 
Set mail = IE.Document.getElementsByTagName("a")(0) ActiveSheet.Cells(i, 2).Value = mail.href

Solution

  • Use a css attribute = value selector with ^ starts with operator

    Debug.Print ie.document.querySelector("[href^='mailto:']").href