赞
踩
import requests from bs4 import BeautifulSoup import openpyxl from selenium import webdriver from selenium.webdriver.common.by import By import time wt = openpyxl.Workbook() ws = wt.create_sheet('sheet11') ws.append(['LIST']) browser = webdriver.Edge() url = 'https://www.freebuf.com/articles/security-management' html = browser.get(url) # print(browser.page_source) nextpagebutton = browser.find_element(By.XPATH, "//li[@class = ' ant-pagination-next']/a") for r in range(1,16): soup = BeautifulSoup(browser.page_source, 'html.parser') spans = soup.find_all('span', class_ = 'title text-line-1') browser.execute_script("arguments[0].click();" ,nextpagebutton) time.sleep(1) print('--------------------正在打印第' + str(r) + '页数据---------------------------') for span in spans: LIST = span.text.strip() print(LIST) ws.append([LIST]) print('success') browser.close() wt.save('demo.xlsx') wt.close()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。