python3爬虫爬百度贴吧decode("utf-8")出错

Python022

python3爬虫爬百度贴吧decode("utf-8")出错,第1张

我写了下代码。没有编码问题,是不是不用decode?

import requests

r1 = requests.get("http://tieba.baidu.com/f?ie=utf-8&kw=python&fr=search")

print(r1.text)

python新手代码是:

1、shuizitiqu.py——————数字提取。

2、socker_ping.py——————长ping 检测网络状态。

3、spider_tieba.py——————爬取百度贴吧图片。

4、tianqi.py——————微信自动回复天气。

5、ticket_searchTrain.py——————12306火车票查询。

6、ticket_stations.py——————12306火车站点。

7、txt.py——————txt文件抽取。

8、weixinhuifu.py——————微信自动回复天气。

9、xlsfile.py——————xls文件提取。

我们在下载文件时,一会会采取urlretrieve或是requests的get方式,

from urllib.request import urlretrieve

urlretrieve(self.url, filename="xxx.png")

但对于连续下载,各个文件保存是需要时间的,而程序运行永运是快于存储的,我怀疑这是水管里流水速度与缸的大小不合适的原因,那可以试试下面这种方式:

r = requests.get(url, stream=True)

with open(local_filename, 'wb') as f:

for chunk in r.iter_content(chunk_size=1024):

if chunk: # filter out keep-alive new chunks

f.write(chunk)

f.flush()