我写了这个脚本,它可以工作,但只抓取页面上的第一个链接,然后停止:
<?php
$handle = fopen("localurls.csv","r");
while(($line=fgetcsv($handle))!==FALSE) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $line[0],
));
$resp = curl_exec($curl);
curl_close($curl);
$regex_body = '%<a href="(.+?)">%s';
$myBody = preg_match($regex_body, $resp, $matches);
$myFile = "localdownload.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $matches[0]);
fclose($fh);
sleep(2);
}
?>
.csv 文件是我有脚本爬网的页面列表。当我运行它时,我得到每个页面上的第一个链接.. IE
<a href="www.google.com">
然后我将它写入一个txt文件。有谁知道修改它以继续在页面上查看代码之间的所有迭代的方法
<a href="
和
">
想了想,在网上找了下怎么实现的,但是没有用。