2022年 11月 16日

Python 自动刷新网页

有些时候刚建的网站,要求达到一定量的浏览量,这个时候你写个小代码就能轻松搞定了,废话不多说直接看下面代码:

import time
from selenium import webdriver  #需pip install selenium


def refresh(url,num):
    filename=r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'
    driver=webdriver.Chrome(filename)
    driver.get(url)
    for i in range(num):
        time.sleep(1)
        driver.refresh()
    driver.close()


if __name__ == '__main__':
    url='https://blog.csdn.net/weixin_40343504/article/details/111492352'
    #url=input('请输入你想刷新的网址:')
    num=int(input('请输入需要刷新次数:'))
    refresh(url,num)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19