生活随笔
收集整理的這篇文章主要介紹了
python 爬取智联招聘
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一個(gè)爬取智聯(lián)的一個(gè)小爬蟲
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):# 設(shè)置 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里面默認(rèn)搜索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):"""處理數(shù)據(jù):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)
運(yùn)行結(jié)果:
總結(jié)
以上是生活随笔為你收集整理的python 爬取智联招聘的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。