摘要: 通常网站通过 实现对某些表单字段(如数据或是登录界面中的认证令牌等)的预填充 使用Scrapy抓取网页时,如果想要预填充或重写像用户名、用户密码这些表单字段, 可以使用 FormRequest.from_response() 方法实现。 下面是使用这种方法的爬虫例子: 阅读全文
posted @ 2017-06-09 11:50 hcw_19 阅读(7721) 评论(1) 推荐(1) 编辑
摘要: 可以使用 yield scrapy.FormRequest(url, formdata, callback)方法发送POST请求。 如果希望程序执行一开始就发送POST请求,可以重写Spider类的start_requests(self) 方法,并且不再调用start_urls里的url。 可以使用 阅读全文
posted @ 2017-06-09 11:37 hcw_19 阅读(14009) 评论(0) 推荐(0) 编辑
摘要: import scrapyfrom scrapy.spider import CrawlSpider,Rulefrom scrapy.linkextractors import LinkExtractorfrom tencent.items import TencentItemclass Tence 阅读全文
posted @ 2017-06-09 11:36 hcw_19 阅读(463) 评论(0) 推荐(0) 编辑
摘要: 通过下面的命令可以快速创建 CrawlSpider模板 的代码: scrapy genspider -t crawl spidername xx.com LinkExtractors Link Extractors 的目的很简单: 提取链接。 每个LinkExtractor有唯一的公共方法是 ext 阅读全文
posted @ 2017-06-09 11:26 hcw_19 阅读(556) 评论(0) 推荐(0) 编辑
摘要: 修改配置文件settings.py,任意位置添加 Log levels Scrapy提供5层logging级别: CRITICAL - 严重错误(critical) ERROR - 一般错误(regular errors) WARNING - 警告信息(warning messages) INFO 阅读全文
posted @ 2017-06-09 11:22 hcw_19 阅读(264) 评论(0) 推荐(0) 编辑
摘要: pipelines.py class xxPipeline(object): def process_item(self, item, spider): con=pymysql.connect(host='localhost,user='',passwd='',db='',charset='utf8 阅读全文
posted @ 2017-06-09 11:11 hcw_19 阅读(1987) 评论(0) 推荐(0) 编辑
摘要: 1.因为使用的yield,而不是return。parse函数将会被当做一个生成器使用。scrapy会逐一获取parse方法中生成的结果,并判断该结果是一个什么样的类型; 2.如果是request则加入爬取队列,如果是item类型则使用pipeline处理,其他类型则返回错误信息。 3.scrapy取 阅读全文
posted @ 2017-06-09 10:54 hcw_19 阅读(742) 评论(0) 推荐(0) 编辑
摘要: 需要在settings.py配置: 阅读全文
posted @ 2017-06-09 10:46 hcw_19 阅读(275) 评论(0) 推荐(0) 编辑
摘要: pipelines.py import json class xxPipeline(object): def __init__(self): self.filename=open("xx.json","wb") def process_item(self, item, spider): jsonte 阅读全文
posted @ 2017-06-09 10:38 hcw_19 阅读(5254) 评论(0) 推荐(0) 编辑
摘要: 1.新建项目 (scrapy startproject xxx):新建一个新的爬虫项目 2.明确目标 (编写items.py):明确你想要抓取的目标 3.制作爬虫 (spiders/xxspider.py):制作爬虫开始爬取网页 4.存储内容 (pipelines.py):设计管道存储爬取内容 阅读全文
posted @ 2017-06-09 10:11 hcw_19 阅读(300) 评论(0) 推荐(0) 编辑