import requests
import time
import traceback
url = [‘https://www.douyu.com/’]
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36’}
count = 0
countUrl = len(url)
访问次数设置
while count < 10000:
try: # 正常运行
for i in range(countUrl):
response = requests.get(url[i], headers=headers)
if response.status_code == 200:
count = count + 1
print('Success ’ + str(count), ‘times’)
time.sleep(75)
except Exception: # 异常
print(‘Failed and Retry’)
traceback.print_exc()
time.sleep(60)
结果如下: