[英]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. 我想使用脚本语言(Javascript,PHP)来完成以下任务。
1)I need to open a new webpage, given a URL, in a different window. 1)我需要在其他窗口中打开一个新的网页,并提供一个URL。
2)Find in its contents a specific link and open it in the same window. 2)在其内容中找到特定链接,然后在同一窗口中将其打开。
Is this possible with Javascript? 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. PS:第一个链接是动态的,因此我只能打一下它才能打开并阅读。 I have noticed that if I open it and then read it,using get_contents for PHP, there are some differences in the content. 我注意到,如果我打开它,然后使用PHP的get_contents读取它,则内容会有一些差异。
You can you PHP Simple HTML DOM Parser to open the page and find the link you need. 您可以PHP简单HTML DOM解析器打开页面并找到所需的链接。
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. 方法“ find”具有类似的jQuery sintax。 And PHP Simple HTML DOM Parser have a good documentation an examples. 并且PHP Simple HTML DOM Parser有一个很好的文档示例。
Hope this help! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.