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)

结果如下: python频繁请求页面

相关文章:

  • 2021-09-14
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2021-08-25
  • 2021-07-16
猜你喜欢
  • 2022-02-22
  • 2021-07-04
  • 2022-12-23
  • 2021-07-19
  • 2021-07-02
相关资源
相似解决方案