gpt4 book ai didi

php - 如何从页面(php)获取所有网址

转载 作者:行者123 更新时间:2023-12-05 08:13:31 25 4
gpt4 key购买 nike

我有一个带有 url 的页面,其中的描述一个接一个地列出(类似于书签/网站列表)。我如何使用 php 从该页面获取所有 url 并将它们写入 txt 文件(每行一个,只有没有描述的 url)?

页面看起来像这样:

Some description

Other description

Another one

我希望脚本的 txt 输出看起来像这样:

http://link.com

http://link2.com

http://link3.com

最佳答案

单向

$url="http://wwww.somewhere.com";
$data=file_get_contents($url);
$data = strip_tags($data,"<a>");
$d = preg_split("/<\/a>/",$data);
foreach ( $d as $k=>$u ){
if( strpos($u, "<a href=") !== FALSE ){
$u = preg_replace("/.*<a\s+href=\"/sm","",$u);
$u = preg_replace("/\".*/","",$u);
print $u."\n";
}
}

关于php - 如何从页面(php)获取所有网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1128774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com