![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
爬虫
xiyucai_cai
这个作者很懒,什么都没留下…
展开
-
xpath 爬取图片
爬去图片import requestsimport refrom lxml import etreefrom urllib3 import request# 页数def page(url,totalpage): changepage=[] for i in range(1,totalpage+1): page_number=re.sub原创 2017-06-28 22:06:39 · 1351 阅读 · 0 评论 -
xpath 百度爬虫
百度搜索关键词 输入搜索的词,输入页数 返回标题、页数、url。import requestsfrom lxml import etreedef gethtml(url): text=requests.get(url).text text=text.replace('<em>','') html=etree.HTML(text) return htmldef原创 2017-07-05 22:45:57 · 427 阅读 · 0 评论 -
urllib
#获取源代码response = request.urlopen('http://www.baidu.com') page = response.read()page = page.decode('utf-8')print(page)urlopen返回对象提供方法:read() , readline() ,readlines() , fileno() , close() :对HTTPRes原创 2017-06-27 19:11:33 · 190 阅读 · 0 评论 -
爬取糗事百科
自己写的爬取代码,还需进一步优化,仅供参考import requestsimport reimport pandas as pdclass spider(): def numbers(link): number=('正在爬取:'+link+'\n\n') return(number) def page(url,totalpage):原创 2017-06-27 19:31:43 · 262 阅读 · 0 评论 -
正则表达式
整理常用的语法findallcsm=re.findall('class=blue>(.*?)</a>',文件名,re.S)原创 2017-06-27 19:30:11 · 156 阅读 · 0 评论 -
scrapy 基本用法
安装文件 lxml、PyOpenssl、Twisted、Pywin32执行 scrapy 创建一个项目: scrapy startproject hello 创建一个爬虫: cd hello scrapy genspider baidu www.baidu.com 执行爬虫: scrapy crawl baidu文件夹里有.cfg文件,是scrapy相关部署信息 items 保存数原创 2017-08-11 14:39:14 · 285 阅读 · 0 评论