#-*-coding:utf-8-*-
import urllib
import urllib2
import re
import json
import threading
import requests
from lxml import etree
from time import sleep,ctime
from Queue import Queue
import lxml
from bs4 import BeautifulSoup
from HTMLParser import HTMLParser
from itertools import product class Get_Html_Pthread(threading.Thread):
def __init__(self,threadid,que):
threading.Thread.__init__(self)
self.threadid = threadid
self.que = que
def run(self):
self.gethtml() def gethtml(self):
while True:
if self.que.empty():
break
else:
page = self.que.get()
print 'qiushibaike spider No'+ str(self.threadid) + 'page = '+ str(page)
url = 'https://www.qiushibaike.com/hot/page/'+str(page)+ '/'
print url
headers = {
'User_agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'If-None-Match': '56abab9faecd14ce1ba95132d661a82db1466c94'}
num_try = 4
while num_try > 0:
num_try -= 1
try:
content = requests.get(url, headers=headers)
data_que.put(content.text)
break
except Exception, e:
print 'qiushi_spider', e
if num_try > 0:
print 'timeout:' + url class Get_Message_Pthread(threading.Thread):
def __init__(self,threadid,que,lock,f):
threading.Thread.__init__(self)
self.threadid = threadid
self.lock = lock
self.que = que
self.f = f
def run(self):
global total,exitFlag_Parser
while exitFlag_Parser == False:
try:
html = self.que.get(False)
if not html:
pass
self.getmessage(html)
self.que.task_done()
except:
pass def getmessage(self,html1):
global total
try:
html = etree.HTML(html1)
result = html.xpath('//div[contains(@id,"qiushi_tag")]')
for each in result:
comment_res = each.xpath('.//span')[0].text
name = each.xpath('.//h2')[0].text
resultq = {
'author':name,
'phrase':comment_res,
}
print resultq
with self.lock:
self.f.write(json.dumps(resultq, ensure_ascii=False).encode('utf-8') + "\n") except Exception,e:
print 'paeser_data',e with self.lock:
total += 1 data_que = Queue()
lock = threading.Lock()
exitFlag_Parser = False
total = 0
def main():
output = open('Phrase.json', 'a')
pageque = Queue(60)
for page in range(1,11):
pageque.put(page)
gethtmlpthread = []
List = [0,1,2,3,4,5]
for threadid in range(5):
thread = Get_Html_Pthread(threadid,pageque)
thread.start()
gethtmlpthread.append(thread) getmessagepthread = [] for threadid in range(5):
thread = Get_Message_Pthread(threadid,data_que,lock,output)
thread.start()
getmessagepthread.append(thread) while not pageque.empty():
pass for t in gethtmlpthread:
t.join() while not data_que.empty():
pass for t in gethtmlpthread:
t.join()
with lock:
output.close() if __name__ == '__main__':
global total
main()
print 'total'+ str(total)

bug-bug-bug的更多相关文章

  1. ORA-01791: not a SELECTed expression 一种是不 bug 的 bug!

    [ora11@lixora ~]$ !sql sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 27 09: ...

  2. oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)

    LAST UPDATE:     1 Dec 15, 2016 APPLIES TO:     1 2 3 4 Oracle Database - Enterprise Edition - Versi ...

  3. 禅道项目管理软件 为提交Bug页面设置bug必填字段

    为提交Bug页面设置bug必填字段 by:授客 QQ:1033553122 测试环境: 禅道项目管理软件7.1.stable版本 注:仅适合windows版 步骤1.找到xampp\zentao\mo ...

  4. FIREDAC(DELPHI10 or 10.1)提交数据给ORACLE数据库的一个不是BUG的BUG

    发现FIREDAC(DELPHI10 or 10.1)提交数据给ORACLE数据库的一个不是BUG的BUG,提交的表名大小写是敏感的. 只要有一个表名字母的大小写不匹配,ORACLE就会认为是一个不认 ...

  5. 浏览器css bug及bug解决方法

    Bugs及解决方案列表(以下实例默认运行环境都为Standard mode): 如何在IE6及更早浏览器中定义小高度的容器? 方法: #test{overflow:hidden;height:1px; ...

  6. 百度地图ip定位,不算bug的bug

    做为一个入行不足两年的菜鸟,能在博客园写下第一篇博客,是需要多大的勇气啊.主要还是怕大神们喷啊.其次自己文笔实在太差了. 哈哈~还请各位大神,口下留情啊. 首先说下我的需求:一个需要城市分站的手机站. ...

  7. 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法

    先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...

  8. 【转】小议Bug敏感度---Bug敏感度的故事(一)

    在测试圈中,相信大家对“Bug敏感度”这一词并不陌生,但是Bug敏感度具体是指什么呢,本文对此关键词进行解读的基础上,对其与软件质量的关系,影响的关键因素,如何提高测试人员的bug敏感度进行分享.(- ...

  9. shit vue-cli & path bug & baseUrl bug

    vue-cli path bug https://cli.vuejs.org/zh/guide/#cli baseUrl bug baseUrl: "././" , https:/ ...

  10. 关于起点中文网的一个我自认为是BUG的BUG(花了我一毛三分钱才实验出来的)

    因为最近在学关于网页的东西,所以便有了每看一个网页,总得先看看这个网页的源码的习惯. 突然我就想到了,起点中文网在看小说的界面是不允许复制粘贴,甚至连点右键都不会有反应, 那么如果我查看源码,能否复制 ...

随机推荐

  1. Codeforces711

    A ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on th ...

  2. 【CF528D】Fuzzy Search(FFT)

    [CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...

  3. 【BZOJ4011】【HNOI2015】落忆枫音(动态规划)

    [BZOJ4011][HNOI2015]落忆枫音(动态规划) 题面 BZOJ 洛谷 Description 「恒逸,你相信灵魂的存在吗?」 郭恒逸和姚枫茜漫步在枫音乡的街道上.望着漫天飞舞的红枫,枫茜 ...

  4. Zabbix概术及基础介绍(一)

    一.Zabbix介绍 Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持.Zabbix 是一个企业级的分布式开源监控方案.Zabbix是一款能够监控各种 ...

  5. Zend Hash table 详解--转

    原文地址:http://www.phppan.com/2009/12/zend-hashtable/ 在PHP的Zend引擎中,有一个数据结构非常重要,它无处不在,是PHP数据存储的核心,各种常量.变 ...

  6. 第13章 MySQL服务器的状态--高性能MySQL学习笔记

    13.1 系统变量 -- 服务器配置变量 MySQL通过SHOW VARIABLES  SQL命令显示许多系统变量. 13.2 状态变量--SHOW STATUS SHOW STATUS 命令会在一个 ...

  7. laravel query builder/ Eloquent builder 添加自定义方法

    上次干这事已经是一年前了,之前的做法特别的繁琐.冗余,具体就是创建一个自定义 Builder 类,继承自 Query\Builder,然后覆盖 Connection 里面获取 Builder 的方法, ...

  8. OD常见指令和快捷键

    声明: 1.本表来自各论坛.博客,欢迎补充讨论 指令 解释 OD汇编指令   NOP 无操作 PUSH 将数据压如堆栈中 POP 出栈(与PUSH相反) PUSHAD 所有通用寄存器的内容按一定顺序压 ...

  9. discuz安装小云app

    小云app登录注册: https://oauth.apps.xiaoyun.com/auth/login.do?authentication_error=1 from:http://lusongson ...

  10. Python基础之面向对象(初级篇)

    概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学 ...