您的位置:首页 > 编程语言 > Python开发

用python试着简单爬取下360图片的图片

2020-02-17 04:37 357 查看
用python试着简单爬取下360图片的图片

 

用python试着简单爬取下360图片的图片

import re
import requests

#抓取源代码
fs = open('source1.txt','wb')
url = "http://image.so.com/"
ctext = requests.get(url)
fs.write(ctext.content)
fs.close()
fs = open('source1.txt','r')
html = fs.read()
fs.close()

#匹配图片网址
pic_url = re.findall('src="(.*?)"',html,re.S)

i=0
for each in pic_url:
if re.findall('jpg',each):
print 'now downloading:'+each
pic = requests.get(each)
fp = open('pic\\'+str(i)+'.jpg','wb')
fp.write(pic.content)
fp.close()
i+=1
if re.findall('png',each):
print 'now downloading:'+each
pic = requests.get(each)
fp = open('pic\\'+str(i)+'.png','wb')
fp.write(pic.content)
fp.close()
i+=1

 

posted on 2016-07-08 20:01 ArvinShaffer 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/ArvinShaffer/articles/5654454.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
awyo96572 发布了0 篇原创文章 · 获赞 0 · 访问量 300 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: