python 抓取页面不显示图片问题
2016-05-19 12:44
316 查看
import sys, urllib import urllib2 query='abc' query = urllib.quote(query) url = "http://wap.sogou.com/web/searchList.jsp?keyword=" + query #url = "https://www.sogou.com/web?query=" + query timeout = 30 headers = { 'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 'Accept':'image/webp,image/*,*/*;q=0.8' } req=urllib2.Request(url,None,headers) res=urllib2.urlopen(req,None,timeout) ret=res.read(); ret = ret.replace("function postHTML(html){", "function postHTML(html){return;") fp = open("web.html","w") #? #fp.write(re.sub(r'(<[^>]*html[^>]*>)', r"\1<base href='"+f.url+"' />", ret, 1)) fp.close()
python抓取搜索结果页面的代码,需要加入上面的正则表达式(加入 <base href/> 标签)
或者加入
<!doctype html><base href='http://wap.sogou.com/web/searchList.jsp?dbg=off&keyword=%E5%B8%8C%E5%B0%94%E8%96%871.5' /><html>
base href 标签 地址 base href 一般放在<head> </head> 之间
相关文章推荐
- Python接口测试
- Python -- 语法和变量
- 349. Intersection of Two Arrays [easy] (Python)
- python phantomjs+ selenium2 抓取动态js网页(版本python2.7+)
- python dict与json转换
- BeaufulSoup获取特定标签下内容的方法
- python SQLAlchemy操作mysql数据库:插入,查询,删除,更新
- python SQLAlchemy创建mysql数据库连接
- Python 进阶——重访 list (二)
- Python3 迭代器与生成器
- python中schedule模块的使用
- python 解析 json文件
- Python中逗号的三种作用
- python BeautifulSoup
- Python中装饰器
- 数据科学部门如何使用Python和R组合完成任务
- python开发目录合并小工具 PathMerge
- Python 资源大全中文版
- python2.7下同步华为云照片的爬虫程序实现
- Python之路【第二十三篇】爬虫