#-*-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. windows主机防护

    Netsh命令-修改网络IP设置 网络管理相关函数 Windows用户相关操作 SID(安全标识符) 策略其他说明 主机防护设置 命令行添加防火墙 防火墙规则 使用SetupDI* API列举系统中的 ...

  2. hdu5279 YJC plays Minecraft 【分治NTT】

    题目链接 hdu5279 题解 给出若干个完全图,然后完全图之间首尾相连并成环,要求删边使得两点之间路径数不超过\(1\),求方案数 容易想到各个完全图是独立的,每个完全图要删成一个森林,其实就是询问 ...

  3. 【agc016D】XOR Replace

    Portal --> agc016D Description ​ 一个序列,一次操作将某个位置变成整个序列的异或和,现在给定一个目标序列,问最少几步可以得到目标序列 ​ Solution ​ 翀 ...

  4. 【DP】【CF31E】 TV Game

    传送门 Description 给你一个长度为\(2n\)的数字,每次可以从左侧选一个数字,加入连接到一个数字\(A\)或另一个数字\(B\)后面.\(A,B\)初始为\(0\).\(A\)与\(B\ ...

  5. php7实现基于openssl的加密解密方法

    还需要注意的是加密字符串长度问题,如果加密字符串长度太长需要进行分段加解密,如下代码: 加密:(公匙加密,私密一般用来解密) function encrypt($originalData){ $pub ...

  6. 111.保留的编号(ing)

    用于做整理的编号,000,111,222,……999

  7. eclipse插件大全(官方)

    eclipse插件大全:http://marketplace.eclipse.org/metrics/successful_installs 各个版本插件: http://download.eclip ...

  8. HDU 6199 DP 滚动数组

    强行卡内存 这题在CF上好像有道极相似的题 可以想到状态设计为dp[f][i][k]表示f在取完i-1时,此时可以取k个或k+1个的状态下的最大值.之前以为n是1e5,自己想不到怎么设计状态真的辣鸡, ...

  9. Python学习笔记(二十九)ThreadLocal

    import threading #创建全局ThreadLocal对象: local_school = threading.local() def process_student(): #获取当前线程 ...

  10. .net core 中 Identity Server 4 Topic 之 Startup

    约定 简称 Id4. Id4在.net core 中的使用符合.net core 的约定架构,即Services来注册服务,middleware方式集成. 1. 配置服务 通过DI注入: public ...