PHP实现简单爬虫的方法,php实现爬虫 本文实例讲述了PHP实现简单爬虫的方法。分享给大家供大家参考。具体如下:
本文实例讲述了PHP实现简单爬虫的方法。分享给大家供大家参考。具体如下:
ion _getUrlContent($url) { $handle = fopen($url, "r"); if ($handle) { $content = stream_get_contents($handle, 1024 * 1024); return $content; } else { return false; } } function _filterUrl($WEB_content) { $reg_tag_a = '/<[a|A].*?href=[\'\"]{0,1}([^>\'\"\ ]*).*?>/'; r e s u l t = p r e gm a t c ha l l ( result = preg_match_all( result=pregmatchall(reg_tag_a, $web_content, m a t c hr e s u l t ) ; i f ( match_result); if ( matchresult);if(result) {
return $match_result[1];
}
}
function main() {
$current_url = “Http://hao123.com/”; //初始url
$fp_puts = fopen(“url.txt”, “ab”); //记录url列表
$fp_gets = fopen(“url.txt”, “r”); //保存url列表
do {
resul t u r l a rr=crawler( result_url_arr = crawler( resulturlarr=crawler(current_url);
if (KaTeX parse error: Expected '}', Got 'EOF' at end of input: … { foreach (result_url_arr as KaTeX parse error: Expected '}', got 'EOF' at end of input: …) { fputs(fp_puts, KaTeX parse error: Undefined control sequence: \n at position 10: url . "\r\̲n̲"); } } }…current_url = fgets($fp_gets, 1024)); //不断获得url
}
main();
?>
--结束END--
本文标题: PHP实现简单爬虫的方法
本文链接: https://lsjlt.com/news/399546.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0