简体   繁体   English

如何从文件中导出特定的A标签。PHP中的[html]

[英]How to export specific A tags from a file.[html] in PHP

i have a html file and some A tags in it. 我有一个html文件和一些A标记。

i need to export some specific A tags from it. 我需要从中导出一些特定的A标签。

here is the whole html file HTML_FILE_LINK 这是整个html文件HTML_FILE_LINK

i want to extract only dl/l/Lucy.2014.Dubbed.Audio.TinyMoviez_co(Onyx).mp3?hash=27bd643109ad5f992c28e10a33afe8dc_159484_26806_3 我只想提取dl/l/Lucy.2014.Dubbed.Audio.TinyMoviez_co(Onyx).mp3?hash=27bd643109ad5f992c28e10a33afe8dc_159484_26806_3

and the other ones like this. 和其他这样的。

how can i do this in php? 我如何在php中做到这一点?

i have tried this : how to get a list of links in a webpage in PHP? 我试过这个: 如何在PHP中获取网页中的链接列表? but didnt work. 但没有工作。

i really need this if anyone could answer i would appreciate . 如果有人可以回答,我真的很需要我,我将不胜感激。

Building on this answer from Parse Website for URLs gives already all a tags 这个答案从大厦解析网站的URL给均已a标签

$code = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($code);
$links = array();
foreach ($doc->getElementsByTagName('a') as $element) {
    if ($element->hasAttribute('href')) {
        $links[] = $element->getAttribute('href');
    }
}

But you want only specific links, so you must check if it satisfies some condition. 但是你要只有特定的联系,所以你必须检查if它满足某些条件。 Extract all relevant parts and see if it matches 提取所有相关部分,看是否匹配

$text = $element->nodeValue;
$link = $element->getAttribute('href');
if ($text == "لینک مستقیم ویژه") {
    echo "$link\n";
}

Putting everything together gives 放在一起就可以

$code = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($code);
foreach ($doc->getElementsByTagName('a') as $element) {
    if ($element->hasAttribute('href')) {
        $text = $element->nodeValue;
        $link = $element->getAttribute('href');
        if ($text == "لینک مستقیم ویژه") {
            echo "$link\n";
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM