python|python 爬虫抓取图片
【python|python 爬虫抓取图片】最好的方法是不看语法不看文档,用什么搜什么
抓取图片
import urllib.request
import re
def dowload_page(url):
request = urllib.request.urlopen(url)
data = https://www.it610.com/article/request.read()
return data
def get_html(url):
request = urllib.request.urlopen(url)
data = request.read()
hmtl =data.decode('UTF-8')
return hmtl
def get_image(html):
regx = r'http://[\S]*\.jpg'
pattern = re.compile(regx)
get_img = re.findall(pattern,repr(html))
print(get_img)
print('aaa')
num =1
for img in get_img:
image = dowload_page(img)
with open('%s.jpg'%num,'wb') as fp:
fp.write(image)
num += 1
print('正在下载第%s张图片'%num)
returnhtml =get_html('http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%B7%E7%BE%B0&fr=ala&ala=1&alatpl=adress&pos=0&hs=2&xthttps=000000')
get_image(html)```
推荐阅读
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- Python基础|Python基础 - 练习1
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)
- Python(pathlib模块)
- python青少年编程比赛_第十一届蓝桥杯大赛青少年创意编程组比赛细则
- Python数据分析(一)(Matplotlib使用)
- 爬虫数据处理HTML转义字符