用python刷CSDN阅读量

发布时间:6个月前热度: 380 ℃评论数:

    需要下载selenium和ChromeDriver,ChromeDriver下载链接:http://chromedriver.storage.googleapis.com/index.html

    代码如下:


#!/usr/bin/evn python
# -*- encoding: utf-8 -*-

"""
@File   :blog.py
@Time   :2019/1/22 8:42
@Author :Robin
@Desc
"""

from selenium import webdriver
import time
from fake_useragent import UserAgent
from bs4 import BeautifulSoup
from selenium.webdriver.support.wait import WebDriverWait

options = webdriver.ChromeOptions()
# 隐藏"Chrome正在受到自动软件的控制"
options.add_argument('disable-infobars')
options.add_argument('user-agent='+UserAgent().random)
# 采用上述配置
browser = webdriver.Chrome(options=options)
# 将浏览器窗口最大化
# browser.maximize_window()
browser.set_window_size(560, 400)
s_time = time.time()
url = list()
a = 0
s_time = time.time()

for i in range(1, 5):
browser.get("https://blog.csdn.net/W07028057/article/list/")
for link in browser.find_elements_by_xpath("//*[@href]"):
if('https://blog.csdn.net/W07028057/article/details/' in link.get_attribute('href') and link.get_attribute('href') not in url):
url.append(link.get_attribute('href'))
print(link.get_attribute('href'))
link.click()
a = a + 1

print(a)

print(time.time() - s_time)
browser.quit()

    说明:把链接换成你的就行了!

python,阅读

  栏目导航

  1. 杂谈
  2. PHP
  3. 建站
  4. MySql
  5. Laravel
  6. ThinkPHP
  7. 面试

  手机扫码访问