import requests
import re
import os
headers={'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36X-Requested-With: XMLHttpRequest'}
"""
context 二进制数据 爬取图片视频使用这个格式
json 对象数据
text 字符串数据
"""
def get_page_response(url):
response=requests.get(url=url,headers=headers)
return response
def get_page_text(response):
page_text=response.content
return page_text
def write_file(page_text,filename):
with open(f"./{filename}.jpg","wb") as fp:
fp.write(page_text)
return None
def main():
url="http://img.itlun.cn/uploads/allimg/180506/1-1P5061TS6-lp.jpg"
filename="1"
page_response=get_page_response(url)
page_text=get_page_text(page_response)
write_file(page_text,filename)
def main1():
url="http://pic.netbian.com/4kmeinv/"
page_text=requests.get(url=url,headers=headers).text
ex=''
img_src_list=re.findall(ex,page_text,re.S)
for src in img_src_list:
src='http://pic.netbian.com'+src
src_data=requests.get(url=src,headers=headers).content
img_name=src.split("/")[-1]
img_Path="./女汉子/"+img_name
with open(img_Path,"wb") as fp:
fp.write(src_data)
print(img_name+"下载成功!!!!!")
if __name__=="__main__":
if not os.path.exists("./女汉子"):
os.mkdir("./女汉子")
main1()