说明:
本文仅用于selenium相关语法的学习,如有任何问题,欢迎大家批评指正~~
crawl数据保存到csv文件:
- 这个是不含job详细信息的【即爬取过程中不涉及页面切换】
- 这个是包含job详细信息的【代码比上边稍微复杂一点,涉及到页面切换】
代码实现【含页面切换】:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
import pandas as pd
from selenium.webdriver.common.keys import Keys
class QCWY:
def __init__(self, keyword, city, maxpagenum): #构造函数
self.keyword = keyword
self.city = city
self.maxpagenum = maxpagenum
def run(self): #执行爬虫任务的函数
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(service=Service(r'E:\Chrome Download\chromedriver_win32\chromedriver.exe'), options=options)
driver.implicitly_wait(10)
driver.get("https://www.51job.com/")
#输入关键字
driver.find_element(By.ID, "kwdselectid").send_keys(self.keyword)
#点击选择城市
driver.find_element