forked from Sunkworld/Trash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtieba_interaction.py
More file actions
executable file
·50 lines (50 loc) · 1.25 KB
/
tieba_interaction.py
File metadata and controls
executable file
·50 lines (50 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/local/bin/python
# coding: utf-8
import requests
import re
import Queue
import time
from threading import Thread
list = []
with open('cookiefile') as f:
cookie = f.read().strip()
s = requests.session()
s.headers.update({'cookie':cookie})
url = 'http://tieba.baidu.com/i/99594746/my_reply?&pn={}'
threads = []
n = 0
que = Queue.Queue()
strg = ''
def search_for(purl):
r = requests.get(purl).content
if re.search(strg, r):
print purl
def worker():
global n
while not que.empty():
search_for(que.get())
n += 1
if n%10==0:
print n/10,
def get_list():
for i in range(1, 31):
cont = s.get(url.format(i)).content
patten = re.findall('/p/(\d+)\?pid=(\d+)', cont)
if re.search(strg, cont):
print url.format(i)
continue
for item in patten:
cur_url = 'http://tieba.baidu.com/p/'+item[0]+'?pid='+item[1]
if cur_url in list:
continue
else:
que.put(cur_url)
list.append(cur_url)
threads.append(Thread(target=get_list))
threads[0].start()
time.sleep(1)
for i in range(10):
threads.append(Thread(target=worker))
threads[i+1].start()
for item in threads:
item.join()