从百度爬取所需要的图片内容:
# -*- coding: utf-8 -*-
import re, os
import requests
from urllib.request import urlretrieve
def download1(url, filename, filepath):
full_name = os.path.join(filepath, filename)
if os.path.exists(full_name):
print("【消息】文件已经存在:", full_name)
try:
pic = requests.get(url, timeout=5)
except:
print('【错误】当前图片无法下载')
return
try:
with open(filepath + "/" + filename, 'wb') as wf:
wf.write(pic.content)
except:
print("【错误】写入失败")
def download2(url, filename, filepath):
full_name = os.path.join(filepath, filename)
if os.path.exists(full_name):
print("【消息】文件已经存在:", full_name)
try:
urlretrieve(url, full_name)
except:
print('【错误】当前图片无法下载')
def search(word, local_path="./data/down/", page=None