import requests
from bs4 import BeautifulSoup
url = 'http://bbs.tianya.cn/post-funinfo-6678943-1.shtml'
pic_url = 'http://img3.laibafile.cn/p/l/229969207.jpg'
# url_content = requests.get(url+pic_url)# 不行
url_content = requests.get(pic_url+url)# 可以
url_content.encoding = url_content.apparent_encoding
import uuid
import os
filename = str(uuid.uuid4()) + '.jpg'
with open(os.path.join(r'D:\Users\Quincy_C\PycharmProjects\S6\Python爬虫', filename), 'wb') as f:
f.write(url_content.content)
'''
方式一:图片奏效
s = requests.session()
response = s.get(image_url+'&'+refer_url,params=self.default_headers, stream=True)#refer_url在前面已定义
for block in response.iter_content(1024):
if not block:
break
handle.write(block)
s.keep_alive = False
方式二:图片不奏效
s = requests.session()
response = s.get(image_url,params=self.default_headers, stream=True)
for block in response.iter_content(1024):
if not block:
break
handle.write(block)
s.keep_alive = False'''
Python3爬虫之突破天涯防盗链
最新推荐文章于 2024-06-23 14:38:06 发布