import urllib.request as urqt
import urllib.parse as urps
from urllib.parse import quote
import requests
import os
import re
import sys
def gethtml(url):
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0"}
res = requests.Session()
res.headers = header
html = res.get(url, timeout = 10, allow_redirects = False).text
return html
def getbyte(url):
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0"}
rep = urqt.Request(url, headers = header)
return urqt.urlopen(rep).read()
def makejpg(url, f):
f.write(getbyte(url))
f.close()
def getintofold(string):
os.chdir(r"D:\信息\python\一些成品\百度图片爬虫")
want = string + "图片"
wehave = os.listdir()
if want in wehave:
os.chdir(want)
else:
os.mkdir(want)
os.chdir(want)
def getall(num, url):
key = re.compile(r'"thumbURL":"(.*?)"')
tot = 0
now = url
while tot < num:
html = gethtml(now)
for now in re.findall(key, html):
tot += 1
if tot > num:
break;
f = open(str(tot) + ".jpg", "wb")
try:
makejpg(now, f)
except BaseException:
print("错误")
tot -= 1
continue;
print("第 " + str(tot) + " 个已下载")
if tot > num:
break
now = url + "&pn=" + str(tot)
def endd():
g.msgbox("感谢使用")
sys.exit()
def init():
now = input("请输入想要的图片: ")
num = input("请输入想要的数量: ")
getintofold(now)
now = quote(now, encoding = 'utf-8')
url = "https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1599885698346_R&pv=&ic=0&nc=1&z=&hd=&latest=©right=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&sid=&word=" + now
getall(int(num), url)
init()
Python爬取百度图片
原创mb60fe8f993dd48 博主文章分类:Python ©著作权
文章标签 Python爬取百度图片 文章分类 Python 后端开发
上一篇:2018 noip AFO? 祭
-
百度云AI
在人工智能的浪潮中,人脸识别技术如同一颗璀璨的明珠,吸引着无数科技爱好者的目光。
百度云 java 人脸识别 -
Python爬取百度图片
新人上路, 老司机们请多多关照, 写的不好的地方, 还请多指教.在很久很久以前, 我是一个苦逼的90后挨踢空穴老人, 一个人的夜里可
python 爬虫 当前页 html 百度 -
python爬虫篇2:爬取百度图片
入门级import requestsimport reimport osfrom urllib import errord
python爬虫 爬取百度图片 python -
Python 取百度图片
【代码】Python 取百度图片。
python 前端 json .net -
史上最简单的spring could 鉴权
一、为什么要使用jwt?在微服务架构下的服务基本都是无状态的,传统的使用session的方式不再适用,如果使用的话需要做同步session机制,所以产生了了一些技术来对微服务架构进行保护,例如常用的鉴权框架Spring Security OAuth2和用Jwt来进行保护,相对于框架而言,jwt较轻,且可以自包含一些用户信息和设置过期时间,省去了Spring Security OAuth2繁琐的步骤
jwt token 过期刷新 jwt如何防止token被窃取 jwt获取token jwt需要存redis吗 未签名的应用程序请求对系统进行无限制访问