":

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的更多相关文章

  1. C# 学习之路--百度网盘爬虫设计与实现(一)

    百度网盘爬虫 现在市面上出现了很多网盘搜索引擎,写这系列博文及爬虫程序的初衷: 更方面的查找资源 学习C# 学习爬虫的设计与实现 记录学习历程 自我监督 能力有限,如有不妥之处,还请各位看官点评.同在 ...

  2. Python编程无师自通PDF高清完整版免费下载|百度网盘

    百度网盘:Python编程无师自通PDF高清完整版免费下载 提取码:cx73 内容介绍 畅销Python编程类入门书,美国亚马逊Kindle编程类排行榜榜一. 作者从文科毕业,通过自学编程转行为专业程 ...

  3. Python编程:从入门到项目实践高清版附PDF百度网盘免费下载|Python入门编程免费领取

    百度网盘:Python编程:从入门到项目实践高清版附PDF免费下载 提取码:oh2g   第一部分 基础知识第1章 起步 21.1 搭建编程环境 21.1.1 Python 2和Python 3 21 ...

  4. Python程序设计(第3版)PDF高清完整版免费下载|百度网盘

    百度网盘:Python程序设计(第3版)PDF高清完整版免费下载 提取码:48u4 内容简介 本书是面向大学计算机科学专业第一门程的教材.本书以Python语言为工具,采用相当传统的方法,强调解决问题 ...

  5. 利用Python爬虫实现百度网盘自动化添加资源

    事情的起因是这样的,由于我想找几部经典电影欣赏欣赏,于是便向某老司机寻求资源(我备注了需要正规视频,绝对不是他想的那种资源),然后他丢给了我一个视频资源网站,说是比较有名的视频资源网站.我信以为真,便 ...

  6. 从零开始学Python网络爬虫PDF高清完整版免费下载|百度网盘

    百度网盘:从零开始学Python网络爬虫PDF高清完整版免费下载 提取码:wy36 目录 前言第1章 Python零基础语法入门 11.1 Python与PyCharm安装 11.1.1 Python ...

  7. 《精通Python网络爬虫》|百度网盘免费下载|Python爬虫实战

    <精通Python网络爬虫>|百度网盘免费下载|Python爬虫实战 提取码:7wr5 内容简介 为什么写这本书 网络爬虫其实很早就出现了,最开始网络爬虫主要应用在各种搜索引擎中.在搜索引 ...

  8. 疯狂Python讲义PDF高清完整版免费下载|百度网盘

    百度网盘:疯狂Python讲义PDF高清完整版免费下载 提取码:uzba 内容简介 <疯狂Python讲义>既是一本适合初学者入门Python的图书(一个8岁的小朋友在未出版前已学习了本书 ...

  9. 从Python开始学编程|PDF百度网盘免费下载|Python新手入门

    百度网盘免费下载:从Python开始学编程|附PDF免费下载 提取码:7nkf 豆瓣评分: 本书封面: 读者评论: 内容简介  · · · · · · 改编自Vamei博客的<Python快速教 ...

随机推荐

  1. 利用百度开发者中心的api实现地图及周边的搜索

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  2. (转)Java字符串

    转自:http://blog.sina.com.cn/s/blog_899678b90101brz0.html 创建字符串有两种方式:两种内存区域(字符串池,堆)1," " 引号创 ...

  3. Android中怎么用this

    在JAVA程序中似乎经常见到“this”,自己也偶尔用到它,但是到底“this”该怎么用,却心中无数!很多人一提起它,就说“当前对象”,可到底什么是当前对象,是什么当前对象,他自己也不清楚.现在让大家 ...

  4. ApiHelper

    public static class ApiHelper { public static ReslultInfo<K> Try<K>(Action<ReslultInf ...

  5. Windwos下常用DOS命令

    1.添加用户命令: net user 用户名 密码 /add 2.将用户加入组的命令: net localgroup administrators 用户名 /add 3.在dos命令行模式下启用用户: ...

  6. 百万级数据查询到datatable中,提示内存溢出

    参考资料: http://group.cnblogs.com/topic/32230.html

  7. Linux 高精確的時序(sleep, usleep,nanosleep) from:http://blog.sina.com.cn/s/blog_533ab41c0100htae.html

    Linux 高精確的時序(sleep, usleep,nanosleep) (2010-04-14 17:18:26) 转载▼ 标签: 杂谈 分类: linux 首先, 我会说不保证你在使用者模式 ( ...

  8. PHP 5.5 新特性

    文章转自:http://wulijun.github.io/2013/07/17/whats-new-in-php-5-5.html http://www.cnblogs.com/yjf512/p/3 ...

  9. array_fill 用给定的值填充数组

    转自:http://www.phpstudy.net/php/165.html PHP array_fill 用给定的值填充数组 array_fill (PHP 4 >= 4.2.0, PHP ...

  10. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...