Python beauthulsoup阅读网页

2024-09-30 08:28:21 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好…我想阅读http://www.nydailynews.com/上的“最受欢迎”专栏。在

Chrome中的代码如下所示:

enter image description here

所以我要:

url = "http://www.nydailynews.com/"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

print soup.find_all(id = 'most-read-content')

但它什么也不返回。在

这里怎么了?是因为“最受欢迎”实际上是闪光灯还是什么?在

谢谢。在


Tags: 代码comhttpurlreadwwwpageurllib2
2条回答

问题是从下载实际文本开始的。 按照您的代码,page.read() 返回空结果

页面的源代码的第一行包含content="text/html; charset=utf-8",但这不是真的,或者代码没有设置为读取utf-8

“问题是服务器返回由Gzip压缩的数据。”

参考如下:

encoding problem in Python when urlopen() a gbk page

相关问题 更多 >

    热门问题