我的python代码输出了错误的html数据
我将此代码片段作为python代码的一部分,用于对特定网站进行爬网(请参见下面的代码)。但令我惊讶的是,输出代码不是html。我正在使用python 3.4我的python代码输出了错误的html数据,python,html,web-crawler,Python,Html,Web Crawler,我将此代码片段作为python代码的一部分,用于对特定网站进行爬网(请参见下面的代码)。但令我惊讶的是,输出代码不是html。我正在使用python 3.4 import urllib.request as ur user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-Agent' : user_agent } s = ur.urlopen('http://www.n
import urllib.request as ur
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
s = ur.urlopen('http://www.nairaland.com')
pl = s.read()
print(pl)
我的代码输出为:
b''
而不是预期的html代码。请指导我如何让这个代码工作。我需要在代码的另一部分的html代码。提前感谢。优秀的
请求
库返回正确的HTML:
import requests
s = requests.get('http://www.nairaland.com')
pl = s.text
print(pl)