一品网
  • 首页

用python实现刷博客园的点击率


前言:可以做,但没必要。

第一步:

通过requests模块,获取网页源代码。再通过正则表达式,获取URL

import requests,re

blog = 'https://www.cnblogs.com/laoluoits/'
res = requests.get(blog).text
links = re.findall('',res)
links.pop(-1)   #最后一个元素不是URL

第二步:

通过webbrowser.open_new_tab()方法打开网页,打开一次算一次点击率。

blog = 'https://www.cnblogs.com/laoluoits/'
res = requests.get(blog).text
links = re.findall('

',res) links.pop(-1) webbrowser.open_new_tab(links[0])

第三步:

终极代码,加入一点随机。让点击间隔时间随机,让点击的URL也随机。

import os,re
import random,time
import webbrowser,requests

blog = 'https://www.cnblogs.com/laoluoits/'
res = requests.get(blog).text
links = re.findall('

',res) links.pop(-1) for x in range(5): i = 0 while i<=9: rt = random.randint(1, 10) blog_id = random.randint(0, len(links)) webbrowser.open_new_tab(links[blog_id]) i += 1 time.sleep(rt) else: os.system('taskkill /F /IM chrome.exe')

python+selenium

相关


Windows : python+selenium(2)打开谷歌Chrome

Python+selenium+PIL截屏后,裁剪图片不准确(Win10)

python+selenium+Robot

关于Python+selenium 定位浏览器弹窗元素

python+selenium的使用

python+selenium 浏览器无界面模式运行

【Python+Selenium】 实现对excel文件的读写操作,轻轻松松一步到位

Python+selenium实现谷歌翻译

python+selenium报错:ElementNotVisibleException: Message: element not interactable

标签

一品网 冀ICP备14022925号-6