要爬的网站:
代码:
import time import pandas as pd from selenium import webdriver def save_csv(arr, csv_filename=None): """Save the data in csv format""" if csv_filename == None: csv_filename="paiming.csv" arr_df = pd.DataFrame({'name': arr}) arr_df.to_csv(csv_filename, float_format='%.3f', index=True, header=True)
driver=webdriver.Chrome() url='https://gkcx.eol.cn/colleges/rank?type=ruanke_rank&fromcoop=360' driver.maximize_window() driver.get(url) li_list=[] arr=[] for j in range(58): time.sleep(2) li_list=driver.find_elements_by_xpath('//*[@id="root"]/div/div[1]/div/div/div/div[1]/div[2]/div/div[3]/ul/li/div[3]/p[1]/span[1]') for i in li_list: arr.append(i.text) print(i.text) driver.find_element_by_css_selector("#root > div > div.container > div > div > div > div:nth-child(1) > div.rank_wrap > div > ul > li.ant-pagination-next").click()
print(arr) save_csv(arr)
运行结果:
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试