爬取csdn的个人博客
全文构思:
本文使用账号密码进行登录,所用到的环境安装
sudo pip3 install selenium
sudo pip3 install pyperclip
除此之外使用了chrome的浏览器,需要下载驱动,自行百度
使用selenium登录了之后,进行全选和复制(进入的是博客管理的界面)
代码中的账号密码
login_mobile.send_keys(‘xxx’)
login_password.send_keys(‘xxx’)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time,os
import pyperclip
class MyCrawl()
def __init__(self):
chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--headless')
self.browser = webdriver.Chrome(chrome_options=chrome_options)
self.wait = WebDriverWait(self.browser, 2)
self.browser.maximize_window()
def get_one_page(self, my_url):
self.browser.get(my_url)
self.parse_page()
def parse_page(self):
titles = self.browser.find_elements_by_css_selector('.article-list-item-txt a')
for title in titles:
my_title = title.text
print("文本标题", my_title)
title.click()
time.sleep(1