1 Star 0 Fork 5

scsme/爬虫-1688商品详情数据

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
download.py 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
gebinda 提交于 2021-07-06 11:17 . feat: 项目初始化
# -*- coding: utf-8 -*-
import requests
import os
from config import proxy
dirName = 'images'
_proxy = requests.get(proxy).text
proxies = {
'http': 'http://' + _proxy
}
# 下载图片
def download(picPath,src, id):
if not os.path.isdir(dirName + '/' + picPath + '_' + str(id)):
os.mkdir(dirName + '/' + picPath + '_' + str(id))
print(dirName + '/' + picPath + '_' + str(id) + "文件夹创建成功")
dir = dirName + '/' + picPath + '_' + str(id) + '/' + str(id) + '.webp'
imageHeader = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
#'accept-encoding': 'gzip, deflate',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'max-age=0',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'none',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
}
try:
pic = requests.get(src,headers=imageHeader,timeout=50,proxies=proxies)
fp = open(dir, 'wb')
fp.write(pic.content)
fp.close()
print(src, "下载成功!")
except requests.exceptions.ConnectionError:
print('Sorrry,image cannot downloaded, url is error{}.'.format(src))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Jakey870/crawler-1688-product-details.git
git@gitee.com:Jakey870/crawler-1688-product-details.git
Jakey870
crawler-1688-product-details
爬虫-1688商品详情数据
master

搜索帮助