urllib2 没有返回完整的网页 [英] urllib2 not returning full webpage
问题描述
我刚开始使用 Python,我正在尝试使用 urllib2 请求站点的 html 源代码.但是,当我尝试从站点获取 html 内容时,我没有获取完整的 html 内容 - 缺少标签.我知道当我在 firebug 中查看站点时,它们会丢失,代码会显示出来.这是由于我请求数据的方式 - 还是由于网站?如果是这样,有没有办法在python中获取站点的完整源代码,然后对其进行解析?
I'm just starting out in Python and I'm trying to request the html source code of a site using urllib2. However when I try and get the html content from a site I'm not getting the full html content - there are tags missing. I know they're missing as when I view the site in firebug the code shows up. Is this due to the way I'm requesting the data - or due to the site? If so is there a way in which I can get the full source code of the site in python, and then parse it?
目前我用来请求内容和我正在尝试的网站的代码是:
Currently the code I'm using to request the content and the site I'm trying is:
import urllib2
url = 'http://marinetraffic.com/ais/'
response = urllib2.urlopen(url)
html = response.read()
print(html)
特别是 - div id="map_area" - 之间的内容缺失.非常感谢任何帮助/指示!
Specifically the content between the - div id="map_area" - is missing. Any help/pointers greatly appreciated!
推荐答案
您得到的数据不完整,因为此页面上的大部分内容都是通过 Javascript 动态生成的...
You are getting incomplete data because most of the content on this page is dynamically generated via Javascript...
这篇关于urllib2 没有返回完整的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!