简体   繁体   中英

Open web-page, get its contents and follow a link that is in there

I want to use a scripting language(Javascript, PHP) to achieve the following task.

1)I need to open a new webpage, given a URL, in a different window.

2)Find in its contents a specific link and open it in the same window.

Is this possible with Javascript? If yes, how is this possible?

PS:The first link is dynamic so I can only to hit it once in order to open it and read it. I have noticed that if I open it and then read it,using get_contents for PHP, there are some differences in the content.

You can you PHP Simple HTML DOM Parser to open the page and find the link you need.

An example for find all links:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';

The method 'find' has similar jQuery sintax. And PHP Simple HTML DOM Parser have a good documentation an examples.

Hope this help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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