pyspider示例代码五:实现自动翻页功能
实现自动翻页功能
示例代码一
#!/usr/bin/env python
# -*- encoding: utf- -*-
# Created on -- ::
# Project: v2ex from pyspider.libs.base_handler import *
#import re class Handler(BaseHandler):
crawl_config = {
} @every(minutes= * )
def on_start(self):
self.crawl('https://www.v2ex.com/', callback=self.index_page, validate_cert=False) @config(age= * * * )
def index_page(self, response):
for each in response.doc('a[href^="https://www.v2ex.com/?tab="]').items():
self.crawl(each.attr.href, callback=self.tab_page, validate_cert=False) @config(age= * * * )
def tab_page(self, response):
for each in response.doc('a[href^="https://www.v2ex.com/go/"]').items():
self.crawl(each.attr.href, callback=self.board_page, validate_cert=False) @config(priority=)
def board_page(self, response):
#实现自动翻页功能
for each in response.doc('a[href^="https://www.v2ex.com/t/"]').items():
url = each.attr.href
if url.find('#reply')>:
url = url[:url.find('#')]
self.crawl(url, callback=self.detail_page, validate_cert=False)
for each in response.doc('a.page_normal').items():
self.crawl(each.attr.href, callback=self.board_page, validate_cert=False) @config(priority=)
def detail_page(self, response):
title = response.doc('h1').text()
content = response.doc('div.topic_content').html().replace('"', '\\"')
tmp = zip(response.doc('a[href^="/member/"]').items(), response.doc('div.reply_content').items())
reply_content = list()
for e1, e2 in tmp:
reply_content.append((e1.text(), e2.text()))
#self.add_question(title, content) #插入数据库
return {
"url": response.url,
"title": title,
"content": content,
"reply_content": reply_content,
}
示例代码二
#!/usr/bin/env python
# -*- encoding: utf- -*-
# Created on -- ::
# Project: tutorial_douban_movie import re
from pyspider.libs.base_handler import * class Handler(BaseHandler):
"""
This is a sample script for: pyspider 爬虫教程(一):HTML 和 CSS 选择器
http://blog.binux.me/2015/01/pyspider-tutorial-level-1-html-and-css-selector/
""" @every(minutes= * )
def on_start(self):
self.crawl('http://movie.douban.com/tag/', callback=self.index_page) @config(age= * * )
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
if 'tag' in each.attr.href:
self.crawl(each.attr.href, callback=self.list_page) @config(age=***, priority=)
def list_page(self, response):
for each in response.doc('HTML>BODY>DIV#wrapper>DIV#content>DIV.grid-16-8.clearfix>DIV.article>DIV>TABLE TR.item>TD>DIV.pl2>A').items():
self.crawl(each.attr.href, priority=, callback=self.detail_page)
# 翻页
for each in response.doc('HTML>BODY>DIV#wrapper>DIV#content>DIV.grid-16-8.clearfix>DIV.article>DIV.paginator>A').items():
self.crawl(each.attr.href, callback=self.list_page) @config(priority=)
def detail_page(self, response):
return {
"url": response.url,
"title": response.doc('HTML>BODY>DIV#wrapper>DIV#content>H1>SPAN').text(),
"rating": response.doc('#interest_sectl > div.rating_wrap.clearbox > div.rating_self.clearfix > strong').text(),
"导演": [x.text() for x in response.doc('a[rel="v:directedBy"]').items()],
}
pyspider示例代码五:实现自动翻页功能的更多相关文章
- ViewPager实现自动翻页功能 --转载出处找不到了,根据自己的理解写个随笔方便以后的记忆以及代码的共享,感谢给我启发的那位高手--第一次写博客哈
xml文件 textview 用于显示图片的标题 viewpager 用于实现翻页效果 <LinearLayout xmlns:android="http://schemas.andr ...
- pyspider示例代码七:自动登陆并获得PDF文件下载地址
自动登陆并获得PDF文件下载地址 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: pdf_sp ...
- pyspider示例代码三:用PyQuery解析页面数据
本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一些 ...
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
转--http://www.2cto.com/kf/201402/277535.html 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版! 2014-02-11 ...
- Python-爬虫之股转系统下载文件自动翻页
上次代码只能抓取一个网页上的链接,本次可以自主设定抓取的页面个数. 代码如下: from selenium import webdriver import os, time class Downloa ...
- C#图片采集软件 自动翻页 自动分类(收集美图必备工具)(一)
网站管理员希望将别人的整站数据下载到自己的网站里或者将别人网站的一些内容保存到自己的服务器上.从内容中抽取相关的字段,发布到自己的网站系统中.有时需要将网页相关的文件也保存到本地,如图片.附件等. 图 ...
- 10款无限滚动自动翻页jquery插件
2012年3月29日 无限滚动自动翻页可以说是web2.0时代的一项堪称伟大的技术,它让我们在浏览页面的时候只需要把滚动条拉到网页底部就能自动显示下一页的 结果,改变了一直以来只能通过点击下一页来翻页 ...
- pyspider示例代码:解析JSON数据
pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下比较经典的示例进行简单讲解,希望对新手有一些帮助. 示例说明: py ...
- vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件
vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件/库 一提到移动端的下拉刷新上拉翻页,你可能就会想到iScroll插件,没错iScroll是一个高性能,资源 ...
随机推荐
- Java的Guava
主要是看代码看到了Table这个类,竟然有两个键! http://www.cnblogs.com/peida/p/3183505.html
- docker容器中搭建kafka集群环境
Kafka集群管理.状态保存是通过zookeeper实现,所以先要搭建zookeeper集群 zookeeper集群搭建 一.软件环境: zookeeper集群需要超过半数的的node存活才能对外服务 ...
- 【原】解决Debug JDK source 无法查看局部变量的问题方案(重新编译rt.jar包)
一.问题阐述 首先我们要明白JDK source为什么在debug的时候无法观察局部变量,因为在jdk中,sun对rt.jar中的类编译时,去除了调试信息,这样在eclipse中就不能看到局部变量的值 ...
- Spring boot @PropertySource, @ImportResource, @Bean
@PropertySource:加载指定的配置文件 /** * 将配置文件中配置的每一个属性的值,映射到这个组件中 * @ConfigurationProperties:告诉SpringBoot将本类 ...
- C++Primer笔记-----继承
==========================================================================day11 面向对象程序设计============ ...
- Mongodb 折腾笔记
简介: Mongodb 是一个由 C++ 语言编写的基于分布式文件存储的数据库,是目前最像关系型数据库的非关系型数据库. 下载地址:https://fastdl.mongodb.org/linux/m ...
- php ip2long 负数问题
官方网站: Note: 因为PHP的 integer 类型是有符号,并且有许多的IP地址讲导致在32位系统的情况下为负数, 你需要使用 "%u" 进行转换通过 sprintf() ...
- poj1182(带权并查集)
题目链接:http://poj.org/problem?id=1182 题意:题目告诉有 3 种动物,互相吃与被吃,现在告诉你 m 句话,其中有真有假,叫你判断假的个数 ( 如果前面没有与 ...
- cf-Round541-Div2-F(并查集+静态链表)
题目链接:http://codeforces.com/contest/1131/problem/F 思路: 很容易看出这是一道并查集的题目,因为要输出每个cage中住的鸟的编号,故采用静态链表.用l[ ...
- hdoj Max Sum Plus Plus(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题意:----最大M子段和问题给定由 n个整数(可能为负整数)组成的序列a1,a2,a3,……, ...