#-*-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. 相机标定 和 单应性矩阵H

    求解相机参数的过程就称之为相机标定. 1.相机模型中的四个平面坐标系: 1.1图像像素坐标系(u,v) 以像素为单位,是以图像的左上方为原点的图像坐标系: 1.2图像物理坐标系(也叫像平面坐标系)(x ...

  2. HDU1536:S-Nim(sg函数)

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. shell unittest工具

    shUnit2:  https://github.com/kward/shunit2 用法非常简单,看看readme就行了.

  4. python基础7--集合

    集合set Python的set集合是一个无序不重复元素集.基本功能包括关系测试和消除重复元素.集合对象还支持union(并集).intersection(交集).difference(差集) 和 s ...

  5. python基础6--目录结构

    为什么要设计好目录结构? "设计项目目录结构",就和"代码编码风格"一样,属于个人风格问题.对于这种风格上的规范,一直都存在两种态度: 一类同学认为,这种个人风 ...

  6. Centos7中使用ipset

      1.禁用firewalld systemctl stop firewalld systemctl disable firewalld   2.安装ipset yum -y install ipse ...

  7. Vue.js随笔一(Webpack + Vue.js开发准备,含VNM、NPM、Node、Webpack等相关工具)

    想入门工具是必须的,这一章将向大家带来vue.js相关的程序安装步骤. ①首先你需要有一个NVM(一个非常好用的Node版本管理器): 1.NVM下载地址:https://github.com/cor ...

  8. html常见页面动画插件

    wow.js页面滚动动画 scrollever.js页面滚动动画 textillate.js页面字体效果 ihover.js手表hover效果插件 loaders.css页面预加载动画

  9. Spring整合JMS(二)——三种消息监听器(转)

    *注:别人那复制来的 1.3     消息监听器MessageListener 在Spring整合JMS的应用中我们在定义消息监听器的时候一共可以定义三种类型的消息监听器,分别是MessageList ...

  10. 2017北京国庆刷题Day5 morning

    期望得分:0+60+60=120 实际得分:0+30+60=90 令g=gcd(X11,X12,X13……) 则行列式可能为D的充要条件为g|D 1.g|D为必要条件: 由定义来算行列式的时候,每一项 ...