正在读取URL';s并解析信息


Reading URL's and parse information

我有一个包含5000行URL的txt文件。我想做的是打开每个url来提取每个url(第一个url)。我的问题是,脚本的第一行打开URL,告诉我有多少链接没有问题。但对于文件中的其余URL,没有显示任何内容。。。数组显示如下内容:

Array
(
)
Array
(
)

我的代码:

$homepage = file_get_contents('***mytxt file****');
$pathComponents = explode(",", trim($homepage)); //line breaker
//echo "<pre>";print_r($pathComponents);echo "</pre>";
$count_nlines = count($pathComponents);
for ($i=0;$i<3;$i++) {
$request_url = $pathComponents[$i];
//echo $request_url . "<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);    // The url to get links from
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We want to get the respone
$result = curl_exec($ch);
$regex='|<a.*?href="(.*?)"|';
preg_match_all($regex,$result,$parts);
$links=$parts[1];
echo "<pre>";print_r($links);echo "</pre>";
curl_close($ch);
}

有什么想法吗?!

看起来你在循环错误的东西。尝试更改:

for ($i=0;$i<3;$i++) {

对此:

for ($i = 0; $i <= count($pathComponents); $i++)