实现自动翻页功能

示例代码一

#!/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示例代码五:实现自动翻页功能的更多相关文章

  1. ViewPager实现自动翻页功能 --转载出处找不到了,根据自己的理解写个随笔方便以后的记忆以及代码的共享,感谢给我启发的那位高手--第一次写博客哈

    xml文件 textview 用于显示图片的标题 viewpager 用于实现翻页效果 <LinearLayout xmlns:android="http://schemas.andr ...

  2. pyspider示例代码七:自动登陆并获得PDF文件下载地址

    自动登陆并获得PDF文件下载地址 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: pdf_sp ...

  3. pyspider示例代码三:用PyQuery解析页面数据

    本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一些 ...

  4. 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!

    转--http://www.2cto.com/kf/201402/277535.html 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版! 2014-02-11     ...

  5. Python-爬虫之股转系统下载文件自动翻页

    上次代码只能抓取一个网页上的链接,本次可以自主设定抓取的页面个数. 代码如下: from selenium import webdriver import os, time class Downloa ...

  6. C#图片采集软件 自动翻页 自动分类(收集美图必备工具)(一)

    网站管理员希望将别人的整站数据下载到自己的网站里或者将别人网站的一些内容保存到自己的服务器上.从内容中抽取相关的字段,发布到自己的网站系统中.有时需要将网页相关的文件也保存到本地,如图片.附件等. 图 ...

  7. 10款无限滚动自动翻页jquery插件

    2012年3月29日 无限滚动自动翻页可以说是web2.0时代的一项堪称伟大的技术,它让我们在浏览页面的时候只需要把滚动条拉到网页底部就能自动显示下一页的 结果,改变了一直以来只能通过点击下一页来翻页 ...

  8. pyspider示例代码:解析JSON数据

    pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下比较经典的示例进行简单讲解,希望对新手有一些帮助. 示例说明: py ...

  9. vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件

    vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件/库 一提到移动端的下拉刷新上拉翻页,你可能就会想到iScroll插件,没错iScroll是一个高性能,资源 ...

随机推荐

  1. 未能同步 iPhone XXX,因为这台电脑不再被授权使用在此iPhone上购买的项目。

    打包生成的ipa文件,安装到手机上,p12和ppf证书都正确,手机的udid也正确.用itunes安装到手机报错. 未能同步 iPhone XXX,因为这台电脑不再被授权使用在此iPhone上购买的项 ...

  2. as3 air 保存文本内容的换行

    private function newData() { var str:String="<root>"; for(var i in charCode_arr) { s ...

  3. vue深入了解组件——Prop

    一.Prop的大小写(camelCase vs kebab-case) HTML中的特性名是大小写不敏感的,所以浏览器会把所有大写字符解释为小写字符.这意味着当你使用DOM中的模板时,cameCase ...

  4. python引用,浅复制,深复制

    引用:可以按照指针理解 copy:只复制父元素,所以如果一个列表嵌套了列表,那么浅复制后原变量和复制后的变量还是引用相同的子元素,子元素修改后,两个变量还会对应改变. deepcopy:复制父元素和子 ...

  5. unity WWW加载进度条

    using UnityEngine; using System.Collections; public class testProgress : MonoBehaviour { void Start ...

  6. Haskell语言学习笔记(65)Data.HashMap

    安装 unordered-containers $ cabal install unordered-containers Installed unordered-containers-0.2.9.0 ...

  7. ubuntu ftp 建立匿名用户 [转]

    转自:http://www.cnblogs.com/cocoajin/p/3761414.html ubuntu server vsftpd 匿名用户上传下载及目录设置 1:vsftpd服务器安装: ...

  8. js中常见的内置对象

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. hibernate中多对多的注解配置

    hibernate多对多的注解配置中的自动生成中间表的配置: @Entity@Table(name="test_student")public class Students { @ ...

  10. 新手C#SQL Server使用记录2018.08.10

    主键(PrimaryKey):主键就是每个数据行(记录)的唯一标识,不会有重复值的列(字段)才能当做主键.一个表可以没有主键,但是这样会很难处理表,因此一般情况表都要设置主键. 主键有两张选用策略,分 ...