抓取网页并检索 JavaScript 变量
我需要抓取一个嵌入了内嵌 javascript 代码的 javascript 数组的网页,例如:
<script>
var videos = new Array();
videos[0] = 'http://myvideos.com/video1.mov';
videos[1] = ....
....
</script>
处理此问题并最终得到这些视频 url 的 PHP 数组的最简单方法是什么?
编辑: 所有视频的扩展名为 .mov。
I need to scrape a web page that has a javascript array embeded in inline javascript code, such as:
<script>
var videos = new Array();
videos[0] = 'http://myvideos.com/video1.mov';
videos[1] = ....
....
</script>
What's the easiest way to approach this and end up with a PHP array of these video urls?
Edit:
All videos are .mov extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点复杂,但它只会获得那些实际上是
videos[0] = 'http://myvideos.com/video1.mov';
形式的链接这里的OP是简化版本:
This is a bit more complicated, but it will get only those links, that are really of the form
videos[0] = 'http://myvideos.com/video1.mov';
After feedback from the OP here is the simplified version:
您可以通过使用 file_get_contents 读取页面来抓取此内容,然后使用正则表达式检索 url。
这是我知道的最简单的方法,特别是如果您知道视频的文件扩展名。
示例:
You can scrape this by reading the page with a file_get_contents then retrieve the urls with a regex.
This is the simplest way i know, especially if you know the file extensions for your videos.
Exemple: