-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_visit_blog.py
41 lines (34 loc) · 1.04 KB
/
auto_visit_blog.py
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
from selenium import webdriver
from queue import Queue
from threading import Thread
class Work:
def __init__(self, url):
option = webdriver.ChromeOptions()
option.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=option)
driver.set_window_size(1920, 1380)
driver.implicitly_wait(5)
self.url = url
driver.get(self.url)
a_list = driver.find_elements_by_xpath("//p/a")
self.q = Queue()
for a in a_list:
self.q.put(a)
def click_a(self, link):
link.click()
while True:
if not self.q.empty():
self.q.get().click()
else:
break
def task(self):
l1 = []
for i in range(10):
link = self.q.get()
t = Thread(target=self.click_a, args=(link,))
t.start()
l1.append(t)
[i.join() for i in l1]
if __name__ == '__main__':
url1 = "https://www.cnblogs.com/louyifei0824/p/9965557.html"
Work(url1).task()