新年快乐,武汉加油
第三步:爬虫
爬虫的思路:通过提供的网址,爬下网址源码,接着于源码中遍历,找寻所有的图片并下载。
爬下源码
运用request库相关函数:
#爬下源码
def pachong(self):
# params 接收一个字典或者字符串的查询参数,字典类型自动转换为url编码,不需要urlencode()
#params = kw,
response = requests.get(self.URL, headers=gHeads)
#
# # 查看响应内容,response.text 返回的是Unicode格式的数据 返回是网页数据
# #print(response.text)
#
# # 查看响应内容,response.content返回的字节流数据
# #print(response.content)
#self.txt = response.content.decode("utf-8")
self.bianma = response.encoding
self.txt = response.content.decode("%s" %response.encoding)
self.txt = self.txt.encode('GBK','ignore').decode('GBK')
print(response.content.decode("%s" %response.encoding))
# # # 查看完