【发布时间】:2014-09-01 23:00:00
【问题描述】:
您好,可以从本站导出为txt文件:
http://bitinfocharts.com/top-100-richest-bitcoin-addresses.html
所有地址?
喜欢:
1BPqtqBKoUjEq8STWmJxhPqtsf3BKp5UyE
1i7cZdoE9NcHSdAL5eGjmTJbBVqeQDwgw
etc...
我写了这段代码:
<?
$html = file_get_contents('http://bitinfocharts.com/top-100-richest-bitcoin-addresses-5.html');
//Create a new DOM document
$dom = new DOMDocument;
//Parse the HTML. The @ is used to suppress any parsing errors
//that will be thrown if the $html string isn't valid XHTML.
@$dom->loadHTML($html);
//Get all links. You could also use any other tag name here,
//like 'img' or 'table', to extract other tags.
$links = $dom->getElementsByTagName('a');
//Iterate over the extracted links and display their URLs
foreach ($links as $link){
//Extract and show the "href" attribute.
echo $link->getAttribute('href'), '<br>';
}
?>
但它会打印所有链接标题,我只需要地址...
【问题讨论】:
标签: php html web-scraping domdocument