python爬虫实例--爬取拉勾网
生活随笔
收集整理的這篇文章主要介紹了
python爬虫实例--爬取拉勾网
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼實例
# -*-.coding: utf-8 -*- # __author__ = 'xiaobai' # Email: 517840374@qq.com import time import re from selenium.webdriver import Chrome # 導入瀏覽器的包 from selenium.webdriver.common.keys import Keys n = 1 # 創建瀏覽器 web = Chrome() # 打開瀏覽器,請求到拉鉤 web.get("https://www.lagou.com") web.find_element_by_xpath('//*[@id="cboxClose"]').click()time.sleep(1) # 找到那個文本框,輸入python,然后點查詢 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并點擊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# 關閉窗口web.close()# 調整窗口到最開始的那個頁面web.switch_to.window(web.window_handles[0])time.sleep(1)轉載于:https://www.cnblogs.com/alex3174/p/11379854.html
總結
以上是生活随笔為你收集整理的python爬虫实例--爬取拉勾网的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深入理解三次握手四次挥手以及使用scap
- 下一篇: ctrl+鼠标左键监听