Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
javasmall committed Jun 2, 2019
1 parent 0a61a23 commit 6d7c764
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 28 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"pythonPath": "/usr/bin/python3",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.fontSize": 16,
"debug.console.fontSize": 16,
"terminal.integrated.fontSize": 16
}
1 change: 1 addition & 0 deletions 爬虫/Include/base/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('jj')
2 changes: 1 addition & 1 deletion 爬虫/Include/spider/handercookie.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import urllib.request as urllib2
import


# 构建一个CookieJar对象实例来保存cookie
cookiejar = cookielib.CookieJar()
Expand Down
26 changes: 26 additions & 0 deletions 爬虫/Include/网易云信/jincheng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from multiprocessing import Pool
from time import sleep,ctime

def worker(msg):
sleep(2)
print(msg)
return ctime()

#创建进程池
pool = Pool(processes = 4)

result = []
for i in range(10):
msg = "hello %d"%i
#将事件放入进程池队列,等待执行
r = pool.apply_async(func = worker,args = (msg,))
result.append(r)

#关闭进程池
pool.close()

#回收
pool.join()

for i in result:
print(i.get()) #获取事件函数的返回值
38 changes: 11 additions & 27 deletions 爬虫/Include/网易云信/wangyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
import time
import threading
from queue import Queue
def loadip():
def loadip():##从代理ip中获取ip 一次若干扩充到queue中
url2 = 'http://piping.mogumiao.com/proxy/api/get_ip_al?appKey=f16367295e284173ae450fc38d9098b3&count=20&expiryDate=0&format=1&newLine=2'
req = requests.get(url2)
date = req.json()
if(date['code'])!='3001':
ipdate2 = date['msg']
global ipdate
ipdate.extend(ipdate2)
for va in ipdate2:
que.put(va)
print(ipdate)

class downspider(threading.Thread):
class downspider(threading.Thread):##线程类
def __init__(self, threadname, que):
threading.Thread.__init__(self)
self.threadname = threadname
Expand All @@ -25,20 +22,17 @@ def run(self):
print('start thread' + self.threadname)
while True:
try:
print(self.name,end='')
toupiaospider(que,self.threadname)
toupiaospider(que,self.threadname)##投票函数
except Exception as e:
print(e,'888')
break
def getproxies():
b = ipdate[0]
def getproxies():#获取ip 拼接成需要的代理格式
b=que.get()
d = '%s:%s' % (b['ip'], b['port'])
global proxies
proxies['http'] = d
global msg
msg = b
return proxies
proxies2={'http':d}
return proxies2
def toupiaospider(que,threadname):
if (que.qsize() < 15): # 拓展ip池
loadip()
Expand All @@ -49,16 +43,13 @@ def toupiaospider(que,threadname):
req = requests.post(url, headers=header, data=formData, proxies=proxies2, timeout=1.5)
res = req.json()
if res['res']==2001 or req.status_code!=200:
#ipdate.remove(msg)
continue
print(threadname,res,que.qsize())
print(threadname,proxies2['http'],res,que.qsize())
except Exception as e:
print('errror',e)
# ipdate.remove(msg)

if __name__ == '__main__':
ipdate = []
msg = {}

proxies = {'http': ''}
stadus = 0
que = Queue()
Expand All @@ -76,19 +67,12 @@ def toupiaospider(que,threadname):
}
loadip()
time.sleep(5)
threadList = ['thread-1','thread-2','thread-3','thread-4','thread-4']
##线程数组 ->启动 ——>等待join
threadList = ['thread-1','thread-2','thread-3','thread-4','thread-4','thread-5']
for j in threadList:
thread = downspider(j, que)
thread.start()
threads.append(thread)
for t in threads:
t.join()
# for i in range(100):
# try:
# toupiaospider()
# except Exception as e:
# print('error')
# try:
# ipdate.remove(msg)
# except Exception as e2:
# print("e2",e2)

0 comments on commit 6d7c764

Please sign in to comment.