900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python + selenium 爬取猎聘招聘网

python + selenium 爬取猎聘招聘网

时间:2021-06-05 13:00:52

相关推荐

python + selenium 爬取猎聘招聘网

Selenium 本是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,模拟用户操作。而这一特性为爬虫开发提供了一个选择及方向,由于其本身依赖于浏览器,所以使用Python的selenium库的前提是:需要下载相应的浏览器驱动程序,这里附上Chromedriver的下载地址:chromedriver

爬取猎聘职位标题 及 标题链接

代码块

from selenium import webdriver启动谷歌浏览器driver=webdriver.Chrome()driver.implicitly_wait(10) # 隐式等待爬取猎聘网driver.get(url='/')定位输入框 并输入 pythondriver.find_element_by_xpath('//*[@id="home"]/div[3]/div[1]/div/div/form/div/div/input').send_keys('python')定位搜索按钮 并点击driver.find_element_by_xpath('//[@id="home"]/div[3]/div[1]/div/div/form/div/button'.click()爬取职位标题 name = driver.find_elements_by_xpath('//*[@id="sojob"]/div[2]/div/div[1]/div[1]/ul/li/div/div[1]/h3/a')# 因为是elements 爬取内容是个列表 需要遍历listall = []for j in range(len(name)):dict = {} text 取出文本dict['name'] = name[j].textget_attribute('href') 取出href属性中的超链接dict['url'] = name[j].get_attribute('href')

效果

输出结果

点击链接进入对应的详情页

接下来可以用超链接 爬取职位描述等信息 在这里我就不爬取了

selenium常用方法

常用方法总结

往期推荐

python中对list去重的方法

flask框架之分页

django框架之分页

机器学习之绘图

爬虫学习之selenium(一)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。