pyspider爬取TripAdvisor
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2017-06-11 10:10:53
# Project: london from pyspider.libs.base_handler import *
import pymongo class Handler(BaseHandler):
crawl_config = {
}
client = pymongo.MongoClient('localhost')
db = client['trip'] @every(minutes=24 * 60)
def on_start(self):
self.crawl('https://www.tripadvisor.cn/Attractions-g186338-Activities-c47-London_England.html', callback=self.index_page) @config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('.listing_title > a').items():
self.crawl(each.attr.href, callback=self.detail_page)
next_page = response.doc('.pagination .nav.next').attr.href
self.crawl(next_page,callback = self.index_page) @config(priority=2)
def detail_page(self, response):
return {
"name":response.doc('h1').text(),
"url": response.url,
'comment':response.doc('.heading_ratings .taLnk').text(),
'address':response.doc('.addressReset > span.format_address').text(),
'phone':response.doc('.phoneNumber').text(),
'duration':response.doc('#MAP_AND_LISTING > div.main_section.listingbar > div > div.above_fold_listing_details > div > div:nth-child(5) > div > div:nth-child(1)').text(),
'instruction':response.doc('#MAP_AND_LISTING > div.main_section.listingbar > div > div.above_fold_listing_details > div > div:nth-child(6) > div > b').text()
}
def on_result(self,result):
if result:
self.save_to_mongo(result) def save_to_mongo(self,result):
if self.db['london'].insert(result):
print('saved to mongo',result)
pyspider爬取TripAdvisor的更多相关文章
- 使用pyspider爬取巨量淘宝MM图片
具体搭建步骤不再赘述,这里主要使用到了fakeagent,phantomjs和proxy pyspider的爬取相当智能,在不能获取图片的时候会适当的暂停一段时间再试探性的爬取,配合fakeagent ...
- 网络字体反爬之pyspider爬取起点中文小说
前几天跟同事聊到最近在看什么小说,想起之前看过一篇文章说的是网络十大水文,就想把起点上的小说信息爬一下,搞点可视化数据看看.这段时间正在看爬虫框架-pyspider,觉得这种网站用框架还是很方便的,所 ...
- PySpider爬取去哪儿攻略数据项目
1 创建项目 点击WEB中的Create创建项目 填入相关项目名和其实爬取URL 创建后进入项目首页 右边 Handler 是pyspider的主类,整个爬虫一个Handler,其中可定义爬虫的爬取. ...
- 用pyspider爬取并解析json字符串
获取堆糖网站所有用户的id 昵称及主页地址 #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2016-06-21 13:57: ...
- pyspider爬取数据存入redis--2.测试数据库连通性
直接上代码 #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2017-10-27 09:56:50 # Project: re ...
- pyspider爬取数据存入es--2.测试数据库连通性
写一个简单案例测试能否将数据写入es #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2017-10-27 08:35:57 ...
- pyspider爬取数据存入mysql--2.测试数据库能否连通
做一个简单的测试,看数据能否存入mysql 1 #!/usr/bin/env python 2 # -*- encoding: utf-8 -*- 3 # Created on 2017-10-26 ...
- pyspider爬取数据导入mysql--1.安装驱动
接上篇,刚装好的pyspider,我们打算大显身手,抓一批数据到mysql中. 然而,出师未捷,提示我们:ImportError: No module named MySQLdb 这是因为还没有安装M ...
- pyspider—爬取视频链接
#!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2015-03-20 09:46:20 # Project: fly_spid ...
随机推荐
- ReactNative的基本组件的认识
通过官网的react-native init myProject,并打开Android Studio的手机模拟器进行调试 下面的代码使用了 Text .Image.View.TextInput和的re ...
- 怎样把Linux的私钥文件id_rsa转换成putty的ppk格式
在Linux VPS下产生的私钥文件putty是不认识的,putty只认识自己的ppk格式,要在这两种格式之间转换,需要PuTTYgen这个程序. puttygen是putty的配套程序,putty的 ...
- 大数据 --> CAP原理和最终一致性
CAP原理和最终一致性 CAP原理和最终一致性(Eventually Consistency)
- Java实现单向链表基本功能
一.前言 最近在回顾数据结构与算法,有部分的算法题用到了栈的思想,说起栈又不得不说链表了.数组和链表都是线性存储结构的基础,栈和队列都是线性存储结构的应用- 本文主要讲解单链表的基础知识点,做一个简单 ...
- synchronized 原理分析
synchronized 原理分析 1. synchronized 介绍 在并发程序中,这个关键字可能是出现频率最高的一个字段,他可以避免多线程中的安全问题,对代码进行同步.同步的方式其实就是隐 ...
- 1013团队Beta冲刺day2
项目进展 李明皇 今天解决的进度 优化了信息详情页的布局:日期显示,添加举报按钮等 优化了程序的数据传递逻辑 明天安排 程序运行逻辑的完善 林翔 今天解决的进度 实现微信端消息发布的插入数据库 明天安 ...
- 在django模板中添加jquery
路径 /project_name /app_name /templates /index.html /project_name setting.py /static /js jquery.js 导入方 ...
- Error contacting service. It is probably not running.
平台:centos-6.3-i386 jdk-7u51 storm 0.9.1 python 2.6.6 hadoop 1.2.1 运行zookeeperd后显示启动成功: JMX enabled ...
- 解决background图片拉伸问题
ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...
- BAT齐聚阿里安全-ASRC生态大会:呼吁联合共建网络安全白色产业链
图说:近日,阿里安全-ASRC生态大会在杭州举行,包括BAT在内的20余家国内知名互联网企业代表,回顾过去一年网络安全面临的问题与挑战,共谋生态安全治理思路. "123456.111111. ...