python爬虫实例--爬取拉勾网
生活随笔
收集整理的這篇文章主要介紹了
python爬虫实例--爬取拉勾网
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼實(shí)例
# -*-.coding: utf-8 -*- # __author__ = 'xiaobai' # Email: 517840374@qq.com import time import re from selenium.webdriver import Chrome # 導(dǎo)入瀏覽器的包 from selenium.webdriver.common.keys import Keys n = 1 # 創(chuàng)建瀏覽器 web = Chrome() # 打開(kāi)瀏覽器,請(qǐng)求到拉鉤 web.get("https://www.lagou.com") web.find_element_by_xpath('//*[@id="cboxClose"]').click()time.sleep(1) # 找到那個(gè)文本框,輸入python,然后點(diǎn)查詢 web.find_element_by_xpath('//*[@id="search_input"]').send_keys('python', Keys.ENTER)alst = web.find_elements_by_class_name("position_link") for a in alst:# 找到H3并點(diǎn)擊a.find_element_by_tag_name("h3").click()web.switch_to.window(web.window_handles[-1])text= web.find_element_by_xpath('//*[@id="job_detail"]/dd[2]').text # 拿文本# 把招聘信息保存到文件中with open(f'需求_{n}.txt', mode = 'w',encoding='utf-8') as f:f.write(text)n += 1# 關(guān)閉窗口web.close()# 調(diào)整窗口到最開(kāi)始的那個(gè)頁(yè)面web.switch_to.window(web.window_handles[0])time.sleep(1)轉(zhuǎn)載于:https://www.cnblogs.com/alex3174/p/11379854.html
總結(jié)
以上是生活随笔為你收集整理的python爬虫实例--爬取拉勾网的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 深入理解三次握手四次挥手以及使用scap
- 下一篇: ctrl+鼠标左键监听