正在通过boss直聘求职,然后见网上有需求boss直聘的职位大数据的,就简单写了一下,发现boss直聘的反爬机制还是比较友好的,首先不需要登陆就可以获取所有的职位信息,其次如果想要避过boss反爬成功访问,使用selenium完全可以直接访问,也就意味着如果使用requests的话,只要仿造一下请求头就可以完成,其中需要注意一下的是,boss直聘对爬虫此类的辨别主要体现在看访问的速率,笔者在完成爬虫时,大概一个ip可以访问3到4页,如果访问速度慢一点的话,也许可以更多,所以最好是可以构造一下ip池,几个ip协同访问就可以完成爬虫,再次把代码放一下吧,和原先一样核心代码我隐藏了,需要的话call我。
上一篇呢写过一个爬取淘宝的代码,有想看的也可以看一下。
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
import requests
import csv
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--proxy-server=http://117.93.19.224:4232 ")
driver = webdriver.Chrome(chrome_options = chromeOptions)
driver.get('https://www.zhipin.com/?sid=sem_pz_sgpc_title')
cxxx='java'
driver.find_element_by_xpath("//*[@id='wrap']/div[4]/div/div/div[1]/form/div[2]/p/input").clear()
driver.find_element_by_xpath("//*[@id='wrap']/div[4]/div/div/div[1]/form/div[2]/p/input").send_keys(cxxx)
driver.maximize_window()
driver.find_element_by_xpath("//*[@id='wrap']/div[4]/div/div/div[1]/form/button").click()
time.sleep(30)
driver.find_element_by_xpath("//*[@class='btn-allcity']").click()
time.sleep(2)
driver.find_element_by_xpath("//li[text()='ABCDE']").click()
time.sleep(2)
driver.find_element_by_xpath("/html/body/div[2]/div[2]/div[2]/div/ul[2]/li[2]/ul/li[1]/span").click()
driver.find_element_by_xpath("//*[@id='filter-box']/div/div[1]/div/form/div[1]/p/input").clear()
driver.find_element_by_xpath("//*[@id='filter-box']/div/div[1]/div/form/div[1]/p/input").send_keys(cxxx)
driver.find_element_by_xpath("//*[@id='filter-box']/div/div[1]/div/form/button").click()
time.sleep(3)
a=driver.find_elements_by_xpath("//span[@class='job-name']")
suma = len(a)
i=0
fy=open('text.txt')
ym=fy.read()
ym=int(ym)
fy.close()
while(i<=suma):
time.sleep(3)
all_handle = driver.window_handles
driver.switch_to_window(all_handle[-1])
a=driver.find_elements_by_xpath("//span[@class='job-name']")
if(i==suma):
js="var q=document.documentElement.scrollTop=100000"
driver.execute_script(js)
driver.find_element_by_xpath("//a[@ka='page-next']").click()
i=0
continue
a[i].click()
i=i+1
all_handle = driver.window_handles
driver.switch_to_window(all_handle[-1])
try:
print("隐藏")
except:
print("出错了!")
driver.close()