jonmrich jonmrich -4 years ago 65
PHP Question

Proper syntax for scraping plugin

I'm using this excellent plugin to scrape some content from a specific website:

An example of what I'm trying to scrape through.

<section class="details">

<div class="address">
<div class="zip-code-country">
<div class="phone">
<a href="tel:+1234567890">(123)456-7890</a>
<li><a href="">Email</a></li>

The relevant part of my code is like this:

foreach($html->find('section.details') as $part2) {

$item2['zip'] = $part2->find(' span', 0)->plaintext; //works perfectly
$item2['phone'] = $part2->find(' a', 0)->plaintext; //works perfectly
$item2['email'] = $part2->find('ul li a[href]', 0)->plaintext; //issue is here
$pieces2[] = $item2;

When I try to get
, it returns the anchor text (i.e., "Email). What I want is for it to return "".

Thoughts on how to get this syntax correct?

Answer Source

You would want to do:

$email= $part2->find('ul li a[href]', 0)->href;
$item2['email'] =str_replace('mailto:', '', $email);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download