简体   繁体   English

我想使用php搜寻器从此文档中获取特定的网址

[英]I want to get specific urls from this document using a php crawler

I have no idea of what to do about this and I'm probably gonna get some down votes. 我不知道该怎么办,我可能会得到一些反对。

I have an web page similar to this: 我有一个与此类似的网页:

<li class="specific-class">
    <a href="http://unknown-url.com">Unknown Link</a>
</li>

I want to crawl a page filled with several other elements I'm not interested in retrieving. 我想抓取一个页面,其中填充了我对检索不感兴趣的其他几个元素。

I want to retrieve only the href attribute in the anchor tag, within the li element and nothing else. 我只想在li元素内的anchor标记中检索href属性,而别无其他。 After which I will then follow the link and get another webpage that has something like this: 之后,我将点击链接并获得另一个具有以下内容的网页:

<h1 class="specific-class">Blah Blah Blah</h1>

So at the end of it all, I'll get whatever is in the h1 element: 因此,最后,我将获得h1元素中的所有内容:

Blah Blah Blah

If you guys could help me get around this I'd greatly appreciate. 如果你们能帮助我解决这个问题,我将不胜感激。 Also, any API's will do nicely. 另外,任何API都会做的很好。

I have this piece of code that gets attributes from an element but I've not been able to get it to crawl elements found within a specific element. 我有这段代码从一个元素获取属性,但是我无法获取它来对特定元素中找到的元素进行爬网。

<?php
include_once('simple_html_dom.php');
$target_url = "https://www.google.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link){
     echo $link->href."<br>";

}

?>

Please read about DOMDocument . 请阅读有关DOMDocument的信息 You can use the methods: getElementsByTagName, getElementById etc. 您可以使用以下方法:getElementsByTagName,getElementById等。

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

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