简体   繁体   中英

Scrape Html with by using simple_html_dom.php library

There is an html document with the following format:

<div....>
  <map name="blah"
           .
           .
   />
  <map name="blah2"
          .
          .
   />
</div>

I want always to retrieve the second map. However, I want to make completely dynamic.

$url = $_GET['url'];
$html_content = getHTML($url);
$html = str_get_html($html_content);

$map = $html->find('map[name=blah2]');

The aforementioned lines are working perfectly fine. But as I mentioned before I don't want to give manually the name. I just want always to take the second map. And moreover I want to retrieve also the name of the map.

Any ideas?

ps The code bellow doesn't work. I've tried this before. And doesn't display the content under the map. However, correctly returns the name of the map

   $map = $html->find('map',1);

What about:

$map = $html->find('map', 1);
echo $map->name;

It is very easy:

$map = $html->find('map',1);
if($map != null)
    $name = $map->name;

You just had to look .

您可以使用jQuery的端口(例如PHPQuery http://code.google.com/p/phpquery/) ,该端口将为您提供eq()选择器,并且通常会启用相当丰富的XML操作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM