php simplehtml
1. Scraping data with PHP Simple HTML DOM Parser
foreach($html->find('a') as $element)
echo $element->href . '<br>';
2. Create DOM from string
$html = str_get_html('<div id="simple">Simple</div><div id="parser">Parser</div>');
3. $html->find('div', 1)->class = 'bar';
4. $html->find('div', 0)->innertext = 'Foo';
5. Match all 'A' tags that have the class attribute equal with 'l'
foreach($html->find('a') as $key => $info)
{
echo ($key + 1).'. '.$info->plaintext."<br />\n";
}
6. $url = 'http://www.google.com/search?hl=en&q=php&btnG=Search';
// Create DOM from URL
$html = file_get_html($url);
// Match all 'A' tags that have the class attribute equal with 'l'
foreach($html->find('a') as $key => $info)
{
echo ($key + 1).'. '.$info->plaintext."<br />\n";
}
页:
[1]