| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2833 人关注过本帖
标题:python-简单的图片爬虫(关键字搜索爬虫)
只看楼主 加入收藏
廉价的咖啡
Rank: 2
来 自:湖北 荆门
等 级:论坛游民
威 望:2
帖 子:53
专家分:17
注 册:2014-10-9
结帖率:72.73%
收藏
 问题点数:0 回复次数:0 
python-简单的图片爬虫(关键字搜索爬虫)
#coding=utf-8

import requests
import re

#guan jian zi sou suo
word = raw_input("Input key word(抱歉!不支持关键字中文输入):")
url = 'http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1475592806271_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word='+word+'#z=0&pn=&ic=0&st=-1&face=0&s=0&lm=-1'
result = requests.get(url)

#huo qu wang ye yuan dai ma
html = requests.get(url).text
pic_url = re.findall('"objURL":"(.*?)",',html,re.S)
i = 0

#yi ci yuan cheng xia zai
for each in pic_url:
    print each
    try:
        pic = requests.get(each,timeout = 10)
    except requests.exceptions.ConnectionError:
        print'【错误】当前图片无法下载'
        continue
    string = 'E:\XIXI\\' +str(i)+'.jpg'
    fp = open(string,'wb')
    fp.write(pic.content)
    fp.close()
    i = i+1
搜索更多相关主题的帖子: python 中文输入 关键字 result 图片 
2016-10-04 23:27
快速回复:python-简单的图片爬虫(关键字搜索爬虫)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014259 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved