|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
import re
import urllib.request
import time
def get_url(url,n):
n=int(n)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"}
base_url='https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E8%A1%A8%E6%83%85%E5%8C%85&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=&ic=&word=%E8%A1%A8%E6%83%85%E5%8C%85&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&fr=&pn='
for i in range(1,n+1):
ul=base_url+str(i*30)
html = requests.get(ul, headers=headers)
html.encoding = 'utf-8'
tar = html.text
link = re.findall(r'"thumbURL":(.*?.jpg)', tar, re.S)
for j in link:
j = j.strip('"')
k=j[-20:]
get_img(j,k)
time.sleep(5)
def get_img(url,name):
urllib.request.urlretrieve(url, "E:\\b\\a\\爬虫百度斗图\\"+name+".jpg" )
url="https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E8%A1%A8%E6%83%85%E5%8C%85&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=&ic=&word=%E8%A1%A8%E6%83%85%E5%8C%85&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&fr=&pn"
n=input('请输入要爬取的页数:')
get_url(url,n)
|
|