Skip to content

Commit 6d7c764

Browse files
committed
add
1 parent 0a61a23 commit 6d7c764

File tree

6 files changed

+62
-28
lines changed

6 files changed

+62
-28
lines changed

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
9+
{
10+
"name": "Python: 当前文件",
11+
"type": "python",
12+
"request": "launch",
13+
"pythonPath": "/usr/bin/python3",
14+
"program": "${file}",
15+
"console": "integratedTerminal"
16+
}
17+
]
18+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.fontSize": 16,
3+
"debug.console.fontSize": 16,
4+
"terminal.integrated.fontSize": 16
5+
}

爬虫/Include/base/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('jj')

爬虫/Include/spider/handercookie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import urllib.request as urllib2
2-
import
2+
33

44
# 构建一个CookieJar对象实例来保存cookie
55
cookiejar = cookielib.CookieJar()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from multiprocessing import Pool
2+
from time import sleep,ctime
3+
4+
def worker(msg):
5+
sleep(2)
6+
print(msg)
7+
return ctime()
8+
9+
#创建进程池
10+
pool = Pool(processes = 4)
11+
12+
result = []
13+
for i in range(10):
14+
msg = "hello %d"%i
15+
#将事件放入进程池队列,等待执行
16+
r = pool.apply_async(func = worker,args = (msg,))
17+
result.append(r)
18+
19+
#关闭进程池
20+
pool.close()
21+
22+
#回收
23+
pool.join()
24+
25+
for i in result:
26+
print(i.get()) #获取事件函数的返回值

爬虫/Include/网易云信/wangyi.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
import time
44
import threading
55
from queue import Queue
6-
def loadip():
6+
def loadip():##从代理ip中获取ip 一次若干扩充到queue中
77
url2 = 'http://piping.mogumiao.com/proxy/api/get_ip_al?appKey=f16367295e284173ae450fc38d9098b3&count=20&expiryDate=0&format=1&newLine=2'
88
req = requests.get(url2)
99
date = req.json()
1010
if(date['code'])!='3001':
1111
ipdate2 = date['msg']
12-
global ipdate
13-
ipdate.extend(ipdate2)
1412
for va in ipdate2:
1513
que.put(va)
16-
print(ipdate)
1714

18-
class downspider(threading.Thread):
15+
class downspider(threading.Thread):##线程类
1916
def __init__(self, threadname, que):
2017
threading.Thread.__init__(self)
2118
self.threadname = threadname
@@ -25,20 +22,17 @@ def run(self):
2522
print('start thread' + self.threadname)
2623
while True:
2724
try:
28-
print(self.name,end='')
29-
toupiaospider(que,self.threadname)
25+
toupiaospider(que,self.threadname)##投票函数
3026
except Exception as e:
3127
print(e,'888')
3228
break
33-
def getproxies():
34-
b = ipdate[0]
29+
def getproxies():#获取ip 拼接成需要的代理格式
3530
b=que.get()
3631
d = '%s:%s' % (b['ip'], b['port'])
3732
global proxies
3833
proxies['http'] = d
39-
global msg
40-
msg = b
41-
return proxies
34+
proxies2={'http':d}
35+
return proxies2
4236
def toupiaospider(que,threadname):
4337
if (que.qsize() < 15): # 拓展ip池
4438
loadip()
@@ -49,16 +43,13 @@ def toupiaospider(que,threadname):
4943
req = requests.post(url, headers=header, data=formData, proxies=proxies2, timeout=1.5)
5044
res = req.json()
5145
if res['res']==2001 or req.status_code!=200:
52-
#ipdate.remove(msg)
5346
continue
54-
print(threadname,res,que.qsize())
47+
print(threadname,proxies2['http'],res,que.qsize())
5548
except Exception as e:
5649
print('errror',e)
57-
# ipdate.remove(msg)
5850

5951
if __name__ == '__main__':
60-
ipdate = []
61-
msg = {}
52+
6253
proxies = {'http': ''}
6354
stadus = 0
6455
que = Queue()
@@ -76,19 +67,12 @@ def toupiaospider(que,threadname):
7667
}
7768
loadip()
7869
time.sleep(5)
79-
threadList = ['thread-1','thread-2','thread-3','thread-4','thread-4']
70+
##线程数组 ->启动 ——>等待join
71+
threadList = ['thread-1','thread-2','thread-3','thread-4','thread-4','thread-5']
8072
for j in threadList:
8173
thread = downspider(j, que)
8274
thread.start()
8375
threads.append(thread)
8476
for t in threads:
8577
t.join()
86-
# for i in range(100):
87-
# try:
88-
# toupiaospider()
89-
# except Exception as e:
90-
# print('error')
91-
# try:
92-
# ipdate.remove(msg)
93-
# except Exception as e2:
94-
# print("e2",e2)
78+

0 commit comments

Comments
 (0)