开发者

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

开发者 https://www.devze.com 2023-02-05 22:43 出处:网络
Id like to get a part of webpage. Let me show you what id like to do. For example, http:// www.xxxxxx.com/page=2

Id like to get a part of webpage. Let me show you what id like to do.

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

As you can see there is a list, and this list shows 50 ads. Please ignore other ones. Every ads have an unique id in their links.

for example:

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

the id number is : 155546130

Okay, id like to get unique id numbers from that page, and echo them to the screen. So, i need to get 50 unique ids from that page. Only id numbers.

well, could you please kindly give me some advice? 开发者_StackOverflow社区which functions should i use? how can i do that job?

Regards.


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]);


You will have to get the HTML and parse it for those IDs. In that case you will have to know exactly where those IDs exist. You can use regular expressions to find links to other pages(websites) and then look for IDs.


PHP has a built-in DOM parser. Poke around the class of functions to reveal what you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消