python爬取百度图片 持久化存储

import requests

import re



shuru= input("请输入")
print("程序开始")

# shuru1= urllib.parse.quote(shuru)


headers={
    
    "User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'}


url="https://image.baidu.com/search/index"

params={
    
    
    "tn": "baiduimage",
    "ipn": "r",
    "ct": "201326592",
    "cl": "2",
    "lm": "-1",
    "st": "-1",
    "fm": "result",
    "fr": "",
    "sf": 1,
    "fmq": "1602587589377_R",
    "pv": "",
    "ic": "undefined",
    "nc": "1",
    "z": "0",
    "hd": "undefined",
    "latest": "undefined",
    "copyright": "undefined",
    "se": 1,
    "showtab": 0,
    "fb": 0,
    "width": "undefined",
    "height": "undefined",
    "face": 0,
    "istype": 2,
    "ie": "utf-8",
    "ctd": "1602587589378^00_933X754",
    "sid": "",
    "word": shuru,
}

html = requests.get(url=url,params=params,headers=headers)
html.encoding='utf-8'
html=html.text



aaaaaa= '"objURL":"(.*?)"'
dizhi = re.findall(aaaaaa,html,re.S)
print(dizhi)

dizhi=dizhi[0]

print(dizhi)


pic=requests.get(dizhi,headers)
name=shuru+'.jpg'
with open(name,"wb") as f:
    f.write(pic.content)





如有需要可在评论区留言。。。

猜你喜欢

转载自blog.csdn.net/qq_45687410/article/details/109103492
今日推荐