Python - 使用 urllib2 检索动态内容
我正在尝试将 YouTube 链接嵌入网页中。当我使用 urllib2 检索页面时,我在响应中看不到该链接。我认为嵌入的视频是通过页面上的脚本检索的,当我使用浏览器时会加载该脚本。如何使用 python 的 urllib2 获得相同的结果?
I am trying to get youtube links embedded in a webpage. When I retrieve the page using urllib2 I don't see the link in the response. I think the embedded video is retrieved by a script on the page which gets loaded when I use a browser. How do I get the same using python's urllib2 ?
A sample webpage is http://busymovies.appspot.com/News.html?id=2965032
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要提取动态生成的(使用 JavaScript)内容,您可以使用 selenium
:
To extract dynamically generated (with javascript) content you could use selenium:
Output
视频正下方有一个名为“直接链接”的链接。现在,如果您打开源代码,您将看到它的结构。
您所需要做的就是解析 HTML 和使用
id=directlink
到达此节点。您可以使用 BeautifulSoup 来实现这一点。你都准备好了...Right below the video there is a link called "Direct Link". Now if you open the source you'll see its structure.
All you need to do is parse the HTML & get to this node with
id=directlink
. You could use BeautifulSoup for that. You are all set...