自动登陆并获得PDF文件下载地址

#!/usr/bin/env python
# -*- encoding: utf- -*-
# Created on -- ::
# Project: pdf_spider import re
from pyspider.libs.base_handler import * class Handler(BaseHandler): global Cookie
Cookie= {"tsclub_bb90_saltkey":"xozcC32l",
"tsclub_bb90_lastvisit":"",
"tsclub_bb90_visitedfid":"",
"tsclub_bb90_ulastactivity":"1428579196%7C0",
"tsclub_bb90_auth":"f9f8KcrDaj3q9aY9OxESFgE2Cz%2BArVk0gZ5jv%2BQohyhctLjeopEZrXU%2FEbsF6pk%2B754%2Fsi5DnB0W%2BmsmLwMvtC3xkWLt",
"tsclub_bb90_lastcheckfeed":"5470207%7C1428579196",
"tsclub_bb90_lip":"122.13.84.73%2C1428579196",
"tsclub_bb90_nofavfid":"",
"pgv_pvi":"",
"pgv_info":"ssi=s5025153920",
"Hm_lvt_ee0d63d2db0dfbf9e0d399bccbd5fce7":"1428461128,1428578830",
"Hm_lpvt_ee0d63d2db0dfbf9e0d399bccbd5fce7":"",
"tsclub_bb90_lastact":"1428581519%09misc.php%09patch",
"tjpctrl":"",
} headers= {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding":"gzip;deflate;sdch",
"Accept-Language":"zh-CN,zh;en-US;q=0.8",
"Cache-Control":"no-cache",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.4368.102 Safari/537.36",
"Host":"club.topsage.com",
"Pragma":"no-cache",
"Refer":"http://club.topsage.com",
"Connection":"keep-alive",
} crawl_config = {
"headers" : headers,
"timeout" : ,
"cookies" : Cookie
} @every(minutes= * )
def on_start(self):
self.crawl('http://club.topsage.com/', callback=self.index_page) @config(age= * * * )
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
if(re.match("http://club\.topsage\.com/forum-.+\.html", each.attr.href, re.U)):
self.crawl(each.attr.href, callback=self.forum_page)
elif re.match("http://club\.topsage\.com/thread-.+\.html", each.attr.href, re.U):
self.crawl(each.attr.href, callback=self.detail_page) @config(age= * * * , priority=)
def forum_page(self, response):
response_url=response.url
#print('forum_page >> response url is ' + response_url) for each in response.doc('a[href^="http://club.topsage.com"]').items():
#if each.attr.href!=response.url:
#detail page
if re.match("http://club\.topsage\.com/thread-.+\.html", each.attr.href, re.U):
self.crawl(each.attr.href, callback=self.detail_page)
#forum forum page
elif re.match("http://club\.topsage\.com/forum-.+\.html", each.attr.href, re.U):
self.crawl(each.attr.href, callback=self.forum_page) #next page
for each in response.doc('html > body > div > div > div > div > a').items():
self.crawl(each.attr.href, callback=self.forum_page) @config(priority=)
def detail_page(self, response):
response_url=response.url
print('detail_page >> response url is ' + response_url) for each in response.doc('table tr > td > a').items():
if(self.is_url_matched(each.attr.href)):
print('attachment url is ' + each.attr.href)
return {
"download_url":each.attr.href,
"file_name":each.text(),
} def is_url_matched(self, url):
if(re.match('^(http|ftp|https)://.+\.(zip|rar|tar|pdf|doc|docx|excel|ppt|pptx)$', url, re.U)):
return True
if(re.match('^http://club\.topsage\.com/forum\.php\?mod=attachment.+', url, re.U)):
return True
return False

pyspider示例代码七:自动登陆并获得PDF文件下载地址的更多相关文章

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

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

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

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

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

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

  4. pyspider示例代码一:利用phantomjs解决js问题

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

  5. pyspider示例代码五:实现自动翻页功能

    实现自动翻页功能 示例代码一 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: v2ex fro ...

  6. pyspider示例代码六:传递参数

    传递参数 示例一 #!/usr/bin/env python # -*- encoding: utf- -*- # vim: ts= sts= ff=unix fenc=utf8: # Created ...

  7. pyspider示例代码四:搜索引擎爬取

    搜索引擎爬取 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: __git_lab_fix fr ...

  8. QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码(转)

    OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...

  9. QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码

    OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...

随机推荐

  1. php使用tcpdf实现在线PDF功能

    今天看书,发现有个例子就是实现php生成pdf格式文件的例子,所以扩展了下百度了下 找了个tcpdf Git上有地址,如果感冒自行下载 https://github.com/tecnickcom/tc ...

  2. 折腾了好久,thinkphp5打开提示加载failed to open stream: No such file or directory in think start.php

    GIT上下载的THINKPHP5记得先 composer update 我就是没update ,折腾了1个小时,才想起来这个事 thinkphp5默认首页打开空白 打开报错提示  提示thinkphp ...

  3. sql 随机取数

    Sql server:      select top 10 * from 表 order by newid()Access:      SELECT top 10 * FROM 表 ORDER BY ...

  4. SqlServer——触发器

    一:触发器基本知识  1.首先必须明确以下几点: 触发器是一种特殊的存储过程,但没有接口(输入输出参数),在用户执行Inserted.Update.Deleted 等操作时被自动触发: 当触发的SQL ...

  5. body{font-size: 62.5%;} 解释

    为什么body{font-size: 62.5%;} 2012-10-25 16:15 16778人阅读 评论(0) 收藏 举报  分类: css问题(17)  在网页设计中我们经常看见body{fo ...

  6. Python模拟登录的几种方法

    目录 方法一:直接使用已知的cookie访问 方法二:模拟登录后再携带得到的cookie访问 方法三:模拟登录后用session保持登录状态 方法四:使用无头浏览器访问 正文 方法一:直接使用已知的c ...

  7. centos7 opencc 安装

    繁体字转换:http://xh.5156edu.com/jtof.php 转换的有问题http://tool.lu/zhconvert/ git网址:https://github.com/BYVoid ...

  8. 导出 java.io.IOException: 权限不够

    项目原先都是开发使用root账号登陆服务器,人肉部署. 今天改成了自动部署,部署之后发现导出用不了了,查看服务器日志提示: 查看项目启动用户是app,推断是app用户的权限不够,导致导出无法在服务器创 ...

  9. new operator

    [new operator] When the code new Foo(...) is executed, the following things happen: A new object is ...

  10. jQuery源码解读二(apply和call)

    一.apply方法和call方法的用法: apply方法: 语法:apply(thisObj,[,argArray]) 定义:应用某一对象的一个方法,用另一个对象替换当前对象. 说明:如果argArr ...