|
本来想爬房产网站的二手房信息,然后用beautifulsoup分析,结果用urllib.request爬取下来的信息全是乱码,用requests就不乱码,不知道为什么,网页源码格式显示是gb2312,编程环境win7 32 python 3.5 在jiebrain里边写的
代码1
import urllib.request
from bs4 import BeautifulSoup
req = 'http://esf.qd.fang.com/house-a01142/i31/'
#print(req)
response = urllib.request.urlopen(req)
the_page = response.read()
t=the_page.decode('gb2312','ignore')
print(t)
运行显示乱码,用print输出还需要encode 吗?
代码2import requests
from bs4 import BeautifulSoup
url="http://esf.qd.fang.com/house-a01142/i31/"
resp=requests.get(url)
print ( resp.text)可以正常运行没有乱码
|
|