bug-bug-bug
#-*-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的更多相关文章
- 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: ...
- 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 ...
- 禅道项目管理软件 为提交Bug页面设置bug必填字段
为提交Bug页面设置bug必填字段 by:授客 QQ:1033553122 测试环境: 禅道项目管理软件7.1.stable版本 注:仅适合windows版 步骤1.找到xampp\zentao\mo ...
- FIREDAC(DELPHI10 or 10.1)提交数据给ORACLE数据库的一个不是BUG的BUG
发现FIREDAC(DELPHI10 or 10.1)提交数据给ORACLE数据库的一个不是BUG的BUG,提交的表名大小写是敏感的. 只要有一个表名字母的大小写不匹配,ORACLE就会认为是一个不认 ...
- 浏览器css bug及bug解决方法
Bugs及解决方案列表(以下实例默认运行环境都为Standard mode): 如何在IE6及更早浏览器中定义小高度的容器? 方法: #test{overflow:hidden;height:1px; ...
- 百度地图ip定位,不算bug的bug
做为一个入行不足两年的菜鸟,能在博客园写下第一篇博客,是需要多大的勇气啊.主要还是怕大神们喷啊.其次自己文笔实在太差了. 哈哈~还请各位大神,口下留情啊. 首先说下我的需求:一个需要城市分站的手机站. ...
- 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法
先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...
- 【转】小议Bug敏感度---Bug敏感度的故事(一)
在测试圈中,相信大家对“Bug敏感度”这一词并不陌生,但是Bug敏感度具体是指什么呢,本文对此关键词进行解读的基础上,对其与软件质量的关系,影响的关键因素,如何提高测试人员的bug敏感度进行分享.(- ...
- shit vue-cli & path bug & baseUrl bug
vue-cli path bug https://cli.vuejs.org/zh/guide/#cli baseUrl bug baseUrl: "././" , https:/ ...
- 关于起点中文网的一个我自认为是BUG的BUG(花了我一毛三分钱才实验出来的)
因为最近在学关于网页的东西,所以便有了每看一个网页,总得先看看这个网页的源码的习惯. 突然我就想到了,起点中文网在看小说的界面是不允许复制粘贴,甚至连点右键都不会有反应, 那么如果我查看源码,能否复制 ...
随机推荐
- 洛谷P1268 树的重量 【构造 + 枚举】
题目描述 树可以用来表示物种之间的进化关系.一棵"进化树"是一个带边权的树,其叶节点表示一个物种,两个叶节点之间的距离表示两个物种的差异.现在,一个重要的问题是,根据物种之间的距离 ...
- 洛谷 P4390 [BOI2007]Mokia 摩基亚 解题报告
P4390 [BOI2007]Mokia 摩基亚 题目描述 摩尔瓦多的移动电话公司摩基亚(\(Mokia\))设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如"用户 ...
- Zabbix概术及基础介绍(一)
一.Zabbix介绍 Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持.Zabbix 是一个企业级的分布式开源监控方案.Zabbix是一款能够监控各种 ...
- 在Mac上安装mysql数据库
安装 登录MySQL网站 用dmg的方式安装.Download MySQL Community Server 或者常规方式,打开官网 : http://www.mysql.com/downloads/ ...
- VS2010中使用Github进行版本控制【补充】
http://blog.csdn.net/softwave/article/details/8499264 前面我在文章<VS2010结合Github进行版本控制>中介绍了VS 2010中 ...
- gitlab配置自动同步
如果需要同步到生产环境,请做额外处理,如自动化测试,测试通过再同步. <?php $project = trim($_GET['project']); if (empty($project)) ...
- HDU 6194 后缀数组
string string string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Spring整合JMS(二)——三种消息监听器(转)
*注:别人那复制来的 1.3 消息监听器MessageListener 在Spring整合JMS的应用中我们在定义消息监听器的时候一共可以定义三种类型的消息监听器,分别是MessageList ...
- html中<meta>标签
这个是html文档一般都有的元素. 1. 介绍 元素基本所有浏览器都支持,它提供页面的元信息,比如描述.关键字.web服务等 位于文档头部的内部,将以名称/值对出现 2. 属性 注意:如果没有name ...
- JAVA多线程提高九:Semaphere同步工具
java 中Semaphere可类比操作系统信号量,硬件资源如IO.内存.磁盘等都是有固定量的,多个程序需要竞争这些资源,没有资源就需要被挂起. 一.类和方法摘要 构造函数: public Semap ...