解决爬虫时网站采用gb2312编码所遇到的乱码问题!

import requests
from bs4 import BeautifulSoupall_url = 'http://www.7160.com/qingchunmeinv/'

# 请求头
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 UBrowser/6.1.2107.204 Safari/537.36'
}

start_html = requests.get(all_url,headers = header)
html = start_html.text.encode('iso-8859-1').decode('gbk')  # 将gb2312转为UTF-8格式
print(html)

 

posted @ 2018-09-26 15:12  追风的小蚂蚁  阅读(909)  评论(0编辑  收藏  举报