百度网盘爬虫Python
for i in range((shares["total_count"]-1)/ONESHAREPAGE):
try:
dbcurr.execute('INSERT INTO urlids(uk, start, limited, type, status) VALUES(%s, %s, %s, 0, 0)' % (uid, str(ONESHAREPAGE*(i+1)), str(ONESHAREPAGE)))
except Exception as ex:
print "E3", str(ex)
pass
if "records" in shares.keys():
for item in shares["records"]:
try:
dbcurr.execute('INSERT INTO share(userid, filename, shareid, status) VALUES(%s, "%s", %s, 0)' % (uid, item['title'], item['shareid'])) #item['title']恰好是文件名称
#返回的json信息:
except Exception as ex:
#print "E33", str(ex), item
pass
else:
print "delete 0", uid, start
dbcurr.execute('delete from urlids where uk=%s and type=0 and start>%s' % (uid, str(start)))
dbcurr.execute('delete from urlids where id=%s' % (id, ))
dbconn.commit()
except Exception as ex:
print "E5", str(ex), id
dbcurr.close()
dbconn.close() #关闭数据库
def worker():
global success, failed
dbconn = mdb.connect(DB_HOST, DB_USER, DB_PASS, 'baiduyun', charset='utf8')
dbcurr = dbconn.cursor()
dbcurr.execute('SET NAMES utf8')
dbcurr.execute('set global wait_timeout=60000')
#以上是数据库相关设置
while True:
#dbcurr.execute('select * from urlids where status=0 order by type limit 1')
dbcurr.execute('select * from urlids where status=0 and type>0 limit 1') #type>0,为非分享列表
d = dbcurr.fetchall()
#每次取出一条数据出来
#print d
if d: #如果数据存在
id = d[0][0] #请求url编号
uk = d[0][1] #用户编号
start = d[0][2]
limit = d[0][3]
type = d[0][4] #哪种类型
dbcurr.execute('update urlids set status=1 where id=%s' % (str(id),)) #状态更新为1,已经访问过了
url = ""
if type == 0: #分享
url = URL_SHARE.format(uk=uk, start=start, id=id).encode('utf-8') #分享列表格式化
#query_uk uk 查询编号
#start
#urlid id url编号
elif type == 1: #订阅
url = URL_FOLLOW.format(uk=uk, start=start, id=id).encode('utf-8') #订阅列表格式化
elif type == 2: #粉丝
url = URL_FANS.format(uk=uk, start=start, id=id).encode('utf-8') #关注列表格式化
if url:
hc_q.put((type, url)) #如果url存在,则放入请求队列,type表示从哪里获得数据
#通过以上的url就可以获得相应情况下的数据的json数据格式,如分享信息的,订阅信息的,粉丝信息的
#print "processed", url
else: #否则从订阅者或者粉丝的引出人中获得信息来存储,这个过程是爬虫树的下一层扩展
dbcurr.execute('select * from user where status=0 limit 1000')
d = dbcurr.fetchall()
if d:
for item in d:
try:
dbcurr.execute('insert into urlids(uk, start, limited, type, status) values("%s", 0, %s, 0, 0)' % (item[1], str(ONESHAREPAGE)))
#uk 查询号,其实是用户编号
#start 从第1条数据出发获取信息
#
dbcurr.execute('insert into urlids(uk, start, limited, type, status) values("%s", 0, %s, 1, 0)' % (item[1], str(ONEPAGE)))
dbcurr.execute('insert into urlids(uk, start, limited, type, status) values("%s", 0, %s, 2, 0)' % (item[1], str(ONEPAGE)))
dbcurr.execute('update user set status=1 where userid=%s' % (item[1],)) #做个标志,该条数据已经访问过了
#跟新了分享,订阅,粉丝三部分数据
except Exception as ex:
print "E6", str(ex)
else:
time.sleep(1)
dbconn.commit()
dbcurr.close()
dbconn.close()
def main():
print 'starting at:',now()
for item in range(16):
t = threading.Thread(target = req_worker, args = (item,))
t.setDaemon(True)
t.start() #请求线程开启,共开启16个线程
s = threading.Thread(target = worker, args = ())
s.setDaemon(True)
s.start() #worker线程开启
response_worker() #response_worker开始工作
print 'all Done at:', now()
百度网盘爬虫Python的更多相关文章
- C# 学习之路--百度网盘爬虫设计与实现(一)
百度网盘爬虫 现在市面上出现了很多网盘搜索引擎,写这系列博文及爬虫程序的初衷: 更方面的查找资源 学习C# 学习爬虫的设计与实现 记录学习历程 自我监督 能力有限,如有不妥之处,还请各位看官点评.同在 ...
- Python编程无师自通PDF高清完整版免费下载|百度网盘
百度网盘:Python编程无师自通PDF高清完整版免费下载 提取码:cx73 内容介绍 畅销Python编程类入门书,美国亚马逊Kindle编程类排行榜榜一. 作者从文科毕业,通过自学编程转行为专业程 ...
- Python编程:从入门到项目实践高清版附PDF百度网盘免费下载|Python入门编程免费领取
百度网盘:Python编程:从入门到项目实践高清版附PDF免费下载 提取码:oh2g 第一部分 基础知识第1章 起步 21.1 搭建编程环境 21.1.1 Python 2和Python 3 21 ...
- Python程序设计(第3版)PDF高清完整版免费下载|百度网盘
百度网盘:Python程序设计(第3版)PDF高清完整版免费下载 提取码:48u4 内容简介 本书是面向大学计算机科学专业第一门程的教材.本书以Python语言为工具,采用相当传统的方法,强调解决问题 ...
- 利用Python爬虫实现百度网盘自动化添加资源
事情的起因是这样的,由于我想找几部经典电影欣赏欣赏,于是便向某老司机寻求资源(我备注了需要正规视频,绝对不是他想的那种资源),然后他丢给了我一个视频资源网站,说是比较有名的视频资源网站.我信以为真,便 ...
- 从零开始学Python网络爬虫PDF高清完整版免费下载|百度网盘
百度网盘:从零开始学Python网络爬虫PDF高清完整版免费下载 提取码:wy36 目录 前言第1章 Python零基础语法入门 11.1 Python与PyCharm安装 11.1.1 Python ...
- 《精通Python网络爬虫》|百度网盘免费下载|Python爬虫实战
<精通Python网络爬虫>|百度网盘免费下载|Python爬虫实战 提取码:7wr5 内容简介 为什么写这本书 网络爬虫其实很早就出现了,最开始网络爬虫主要应用在各种搜索引擎中.在搜索引 ...
- 疯狂Python讲义PDF高清完整版免费下载|百度网盘
百度网盘:疯狂Python讲义PDF高清完整版免费下载 提取码:uzba 内容简介 <疯狂Python讲义>既是一本适合初学者入门Python的图书(一个8岁的小朋友在未出版前已学习了本书 ...
- 从Python开始学编程|PDF百度网盘免费下载|Python新手入门
百度网盘免费下载:从Python开始学编程|附PDF免费下载 提取码:7nkf 豆瓣评分: 本书封面: 读者评论: 内容简介 · · · · · · 改编自Vamei博客的<Python快速教 ...
随机推荐
- Win8下安装.Net3.5的完美策略
在Win8中运行之前的.Net版本(4.0以下)写的程序时,会出现需要安装.Net 3.5的提示.但是你使用在线安装的话是无法成功的,在线升级会遇到错误0x800F0906.明明Win8系统集成的是. ...
- BaKoMa Tex Word 的使用
数学论文编排软件,付费,但是可以这么处理,安装好后不要马上打开,进入影子系统的时候再运行它,这样每次都是全新的, 优势是 WYSIWYG,所见即所得, 中文输入, \documentclass{art ...
- input 获取当前id,name
<input name=" src="toright.png" value="mp3"> <script language=&quo ...
- js blind使用
$("#music_up").bind("click",showData()); $("#music_up").bind("cli ...
- PageBase
namespace Webform.App { public class PageBase : System.Web.UI.Page { } public interface IService< ...
- Yii2-admin RBAC权限管理的实现
原文地址:http://www.open-open.com/lib/view/open1434638805348.html http://wlzyan.blog.163.com/blog/stat ...
- elasticsearch集群管理工具head插件(转)
elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es 插件安装方法1: 1.elasticsearc ...
- 关于hibernate纯sql查询返回结果集的问题(hbm.xml中不写多表关联)
相信用过hibernate的兄弟们都会因为多表复杂查询后,为返回的结果如何组装到一个VO中而烦恼不已.我也不停的为此而烦恼,但是在看了hibernate的transform后,感觉这个方法还挺管用的. ...
- Hibernate uniqueResult方法的使用
以前写代码,总免不了编写登陆部分.在获取user的时候,只可能返回一个user实例,或者为null.以前使用以下方法实现.public User get(String id){ Sessio ...
- kafka C客户端librdkafka producer源码分析
from:http://www.cnblogs.com/xhcqwl/p/3905412.html kafka C客户端librdkafka producer源码分析 简介 kafka网站上提供了C语 ...