来源 : 网络营销行业践行者 时间 : 2018/2/27 12:30:45
import requests from bs4 import BeautifulSoup def pachong(url): req = requests.get(url) req.encoding = req.apparent_encoding
html =req.text print(html) soup = BeautifulSoup(html, "html.parser")
其中 rep.encoding 根据响应头中的 charset 判断网站编码,如果没有设置则默认返回 iso-8859-1 编码,而req.apparent_encoding 则通过网页内容来判断其编码。令req.encoding=req.apparent_encoding就不会出现乱码问题。
Copyright 2017 济南卓汇信息技术有限公司 济南卓汇信息技术有限公司
地址:济南市历城区永大商务楼213
电话:18660772755
QQ:94184083
Email:94184083@qq.com
18660772755