简体   繁体   English

您如何使用php从远程获取网页的一部分?

[英]How do you get a part of webpage from remote by using php?

Id like to get a part of webpage. 我想获得网页的一部分。 Let me show you what id like to do. 让我告诉你id喜欢做什么。

For example, http:// www.xxxxxx.com/page=2 例如,http:// www.xxxxxx.com/page=2

As you can see there is a list, and this list shows 50 ads. 如您所见,有一个列表,该列表显示了50个广告。 Please ignore other ones. 请忽略其他。 Every ads have an unique id in their links. 每个广告的链接中都有唯一的ID。

for example: 例如:

http:// xxx.com/-iid-155546130 http:// xxx.com/-iid-155546130

the id number is : 155546130 ID号为:155546130

Okay, id like to get unique id numbers from that page, and echo them to the screen. 好的,id喜欢从该页面获取唯一的ID号,并将它们回显到屏幕上。 So, i need to get 50 unique ids from that page. 因此,我需要从该页面获取50个唯一ID。 Only id numbers. 仅身份证号码。

well, could you please kindly give me some advice? 好吧,能否请您给我一些建议? which functions should i use? 我应该使用哪些功能? how can i do that job? 我该怎么做?

Regards. 问候。

You will have to get the HTML and parse it for those IDs. 您将必须获取HTML并解析这些ID。 In that case you will have to know exactly where those IDs exist. 在这种情况下,您将必须确切知道这些ID的位置。 You can use regular expressions to find links to other pages(websites) and then look for IDs. 您可以使用正则表达式查找到其他页面(网站)的链接,然后查找ID。

PHP has a built-in DOM parser . PHP具有内置的DOM解析器 Poke around the class of functions to reveal what you're looking for. 在功能类别中四处寻找,以显示您要查找的内容。

Fetch the page with: 通过以下方式获取页面:

$html = file_get_contents($url);  // or curl if you like it cumbersome

And use a regex to get the numbers: 并使用正则表达式获取数字:

preg_match_all("/-iid-(\d+)/", $html, $m);  // could be more precise
print_r($m[1]);

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

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