21,887
社区成员
发帖
与我相关
我的任务
分享
<?php
if(!file_exists("ceshi.txt")){
fopen("ceshi.txt","w");
}
$txt = file_get_contents("http://www.baidu.com");//获得网页内容后 可以用正则匹配抓取那个链接 思路就是这样
preg_match_all("|<a\s+href=(.+?)>(.+?)</a>|",$txt,$match);
var_dump($match);//数组中有单独提取的链接和文字 可以自己处理
foreach ($match[0] as $val){
echo htmlspecialchars($val)."<br>";
$str .= $val;
}
file_put_contents("ceshi.txt",$str);
?>
<?php
if(!file_exists("ceshi.txt")){
fopen("ceshi.txt","w");
}
$txt = file_get_contents("http://www.baidu.com");//获得网页内容后 可以用正则匹配抓取那个链接 思路就是这样
preg_match_all("|<a\s+href=(?<url>.+?)>(?<content>.+?)</a>|",$txt,$match);
var_dump($match);//数组中有单独提取的链接和文字 可以自己处理
foreach ($match[0] as $val){
echo htmlspecialchars($val)."<br>";
$str .= $val;
}
file_put_contents("ceshi.txt",$str);
?>