pycharm 2022.2
python 3.10
chromedriver
selenium 4.3.0
pymysql 0.7.11
mysql 5.7
import os
import pymysql
import datetime
from selenium import webdriver
from selenium.webdrivermon.by import By
url = '=realtime'
res = (url)
print(res.status_code)
返回状态码为200即为接口通畅
options = webdriver.ChromeOptions()
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument('--start-maximized')
options.add_argument('disable-infobars')
drivers = webdriver.Chrome(options=options)
('=realtime')
tittleList = []
exponentList = []
for tittleIndex in range(1, 32):drivers.implicitly_wait(10)xpath = '//*[@id="sanRoot"]/main/div[2]/div/div[2]/div[' + str(tittleIndex) + ']/div[2]/a/div[1]'tittle = drivers.find_element(By.XPATH, xpath).texttittleList.append(tittle)
for exponentIndex in range(1, 32):drivers.implicitly_wait(10)xpath = '//*[@id="sanRoot"]/main/div[2]/div/div[2]/div[' + str(exponentIndex) + ']/div[1]/div[2]'exponent = drivers.find_element(By.XPATH, xpath).textexponentList.append(exponent)
CREATE TABLE baidu_info(id int NOT NULL AUTO_INCREMENT,tittle varchar(150),exponent varchar(128),PRIMARY KEY(id))ENGINE=InnoDB;
config = {'host': '127.0.0.1','user': 'root','password': 'root','database': 'baidu'
}
db = t(**config)
cursor = db.cursor()
for index, element in enumerate(tittleList):sql = 'INSERT INTO baidu_info(tittle,exponent) VALUES("' + tittleList[index] + '","' + exponentList[index] + '")'print(ute(sql)dbmit()
本文发布于:2024-02-02 17:06:34,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686479545227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |