生活随笔
收集整理的這篇文章主要介紹了
python 爬取智联招聘
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個爬取智聯的一個小爬蟲
python版本:python3.7
依賴模塊:selenium、pyquery
廢話少說,上代碼
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from pyquery import PyQuery as pq
import timeclass ZhiLian:def __init__(self):# 設置 chrome 無界面化模式self.chrome_options = Options()self.chrome_options.add_argument('--headless')self.chrome_options.add_argument('--disable-gpu')self.driver = webdriver.Chrome(chrome_options=self.chrome_options)def get_url(self, search='python'):"""獲取搜索職位的url, demo里面默認搜索python:param search::return:"""self.driver.get("https://www.zhaopin.com/")element = self.driver.find_element_by_class_name("zp-search__input")element.send_keys(f"{search}")element.send_keys(Keys.ENTER)# 切換窗口self.driver.switch_to.window(self.driver.window_handles[1])# 等待js渲染完成后,在獲取htmltime.sleep(4)html = self.driver.find_element_by_xpath("//*").get_attribute("outerHTML")return htmldef data_processing(self):"""處理數據:return:"""html = self.get_url()doc = pq(html)contents = doc(".contentpile__content__wrapper")for content in contents.items():jobname = content(".contentpile__content__wrapper__item__info__box__jobname__title").text()companyname = content(".contentpile__content__wrapper__item__info__box__cname").text()saray = content(".contentpile__content__wrapper__item__info__box__job__saray").text()demand = content(".contentpile__content__wrapper__item__info__box__job__demand").text()yield jobname, companyname, saray, ",".join(demand.split("\n"))datas = ZhiLian().data_processing()
for data in datas:print(data)
運行結果:
總結
以上是生活随笔為你收集整理的python 爬取智联招聘的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。