pyspider示例代码七:自动登陆并获得PDF文件下载地址
自动登陆并获得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文件下载地址的更多相关文章
- pyspider示例代码:解析JSON数据
pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下比较经典的示例进行简单讲解,希望对新手有一些帮助. 示例说明: py ...
- pyspider示例代码三:用PyQuery解析页面数据
本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一些 ...
- pyspider示例代码二:解析JSON数据
本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下 ...
- pyspider示例代码一:利用phantomjs解决js问题
本系列文章主要记录和讲解pyspider的示例代码,希望能抛砖引玉.pyspider示例代码官方网站是http://demo.pyspider.org/.上面的示例代码太多,无从下手.因此本人找出一下 ...
- pyspider示例代码五:实现自动翻页功能
实现自动翻页功能 示例代码一 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: v2ex fro ...
- pyspider示例代码六:传递参数
传递参数 示例一 #!/usr/bin/env python # -*- encoding: utf- -*- # vim: ts= sts= ff=unix fenc=utf8: # Created ...
- pyspider示例代码四:搜索引擎爬取
搜索引擎爬取 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: __git_lab_fix fr ...
- QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码(转)
OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...
- QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码
OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...
随机推荐
- 1.vue和react的区别
1.个人感觉Vue好用,react不咋地呀. 2.(网上搜的)Vue的解决方案适用于小型应用,但对于对于大型应用而言不太适合.
- mysql 数据字典
Information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式. desc tb_name ,describe tb_name,show columns from tb_ ...
- IOUtils总结
参考:https://www.cnblogs.com/xing901022/p/5978989.html 常用的静态变量 在IOUtils中还是有很多常用的一些变量的,比如换行符等等 public s ...
- MAC CURL : Error:35 SSL certificate problem: Couldn't understand the server certificate format
起因,使用极光推送最新的版本,里面curl使用https请求,而导致证书出错.一看就懵逼了,从来没遇到过这样的问题,二话不说直接百度,然后就更加懵逼了,搜出来的没有中文内容,对于我这种英文渣来说,简直 ...
- attr 修改IMG src
jQuery修改img的src的方法:$("#img_id").attr("src","new_src"); 定义和用法 attr() 方法 ...
- mysql 变量名称不能与表字段一致
my sql的变量名称不能与表字段名称相同不然会有各种异常问题 啃爹
- Ansible playbooks
Playbook是Ansible的配置,部署和编排语言. 他们可以描述您希望远程系统执行的策略,或一般IT流程中的一组步骤. 如果Ansible modules是您workshop的工具,则playb ...
- pymongo的常用操作
环境:pymongo3.0.3,python3 以下是我整理的一些关于pymongo的操作,网上很多是用pymongo.Connecion()去连接数据库的,但是我这里连接一直提示没有这个包,如果大家 ...
- 97. Interleaving String (String; DP)
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- 【校招面试 之 剑指offer】第9-1题 用两个栈实现一个队列
#include<iostream> #include<stack> using namespace std; template <typename T> void ...