欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过多线程的方式刷csdn浏览量

程序员文章站 2022-04-15 20:57:10
1 import requests 2 import time 3 import threading 4 def Thread(): 5 url = ['https://blog.csdn.net/qq_40822132/article/details/105361968', 6 'https:// ......
 1 import requests
 2 import time
 3 import threading
 4 def thread():
 5     url = ['https://blog.csdn.net/qq_40822132/article/details/105361968',
 6            'https://blog.csdn.net/qq_40822132/article/details/105359571',
 7            'https://blog.csdn.net/qq_40822132/article/details/105359476',
 8            'https://blog.csdn.net/qq_40822132/article/details/105269815',
 9            'https://blog.csdn.net/qq_40822132/article/details/105260175',
10            'https://blog.csdn.net/qq_40822132/article/details/105070726',
11            'https://blog.csdn.net/qq_40822132/article/details/105028436',
12            'https://blog.csdn.net/qq_40822132/article/details/104739744',
13            'https://blog.csdn.net/qq_40822132/article/details/104373265',
14            'https://blog.csdn.net/qq_40822132/article/details/104372185',
15            'https://blog.csdn.net/qq_40822132/article/details/105631011',
16            'https://blog.csdn.net/qq_40822132/article/details/105243506',
17            'https://blog.csdn.net/qq_40822132/article/details/105064770',
18            'https://blog.csdn.net/qq_40822132/article/details/105028667',
19            'https://blog.csdn.net/qq_40822132/article/details/104373801',
20            'https://blog.csdn.net/qq_40822132/article/details/104373515',
21            'https://blog.csdn.net/qq_40822132/article/details/104373057',
22            'https://blog.csdn.net/qq_40822132/article/details/104372588',
23            'https://blog.csdn.net/qq_40822132/article/details/104371595',
24            'https://blog.csdn.net/qq_40822132/article/details/104371081',
25            'https://blog.csdn.net/qq_40822132/article/details/104302215',
26            'https://blog.csdn.net/qq_40822132/article/details/104372811',
27            'https://blog.csdn.net/qq_40822132/article/details/104303954',
28            'https://blog.csdn.net/qq_40822132/article/details/104303482',
29            'https://blog.csdn.net/qq_40822132/article/details/104302722',
30            'https://blog.csdn.net/qq_40822132/article/details/104300872',
31            'https://blog.csdn.net/qq_40822132/article/details/104300620',
32            'https://blog.csdn.net/qq_40822132/article/details/104300124',
33            'https://blog.csdn.net/qq_40822132/article/details/104299547',
34            'https://blog.csdn.net/qq_40822132/article/details/104143837',
35            'https://blog.csdn.net/qq_40822132/article/details/103959989',
36            'https://blog.csdn.net/qq_40822132/article/details/103956114',
37            'https://blog.csdn.net/qq_40822132/article/details/103947197',
38            'https://blog.csdn.net/qq_40822132/article/details/103947136',
39            'https://blog.csdn.net/qq_40822132/article/details/103750154',
40            'https://blog.csdn.net/qq_40822132/article/details/103750109',
41            'https://blog.csdn.net/qq_40822132/article/details/103750079',
42            'https://blog.csdn.net/qq_40822132/article/details/105743025',
43            'https://blog.csdn.net/qq_40822132/article/details/103960533',
44            'https://blog.csdn.net/qq_40822132/article/details/103750037',
45            'https://blog.csdn.net/qq_40822132/article/details/103749970',
46            'https://blog.csdn.net/qq_40822132/article/details/103749904',
47            'https://blog.csdn.net/qq_40822132/article/details/103748249',
48            'https://blog.csdn.net/qq_40822132/article/details/103748165']
49     headers = {
50         'user-agent': 'mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/73.0.3683.103 safari/537.36'}
51     count = 0
52     counturl = len(url)
53     # 访问次数设置
54     while count < 100000:
55         try:  # 正常运行
56             for i in range(counturl):
57                 response = requests.get(url[i], headers=headers)
58                 if response.status_code == 200:
59                     count = count + 1
60                     print('success ' + str(count), 'times')
61             time.sleep(20)
62         except exception:  # 异常
63             print('failed and retry')
64             time.sleep(30)
65 t1=threading.thread(target=thread)
66 t2=threading.thread(target=thread)
67 t3=threading.thread(target=thread)
68 t4=threading.thread(target=thread)
69 t1.start()
70 t2.start()
71 t3.start()
72 t4.start()