from selenium import webdriver
import pandas as pd
from pandas import DataFrame
import time
bor= webdriver.Chrome()
def wab(www):
bor.get(www)
a1=[]
for i in range(90):
b1=bor.find_elements_by_class_name('contentpile__content__wrapper__item__info__box__job__saray')
a1.append(b1[i].text)
a2=[]
for i in range(90):
#注意这里用了一个format() 因为每条数据的div{}不一样
kk1=bor.find_element_by_xpath('//*[@id="listContent"]/div{}/div/a/div[1]/div[2]/a'.format([i+1]))
a2.append( kk1.text)
a3=[]
for i in range(90):
b1=bor.find_elements_by_class_name('contentpile__content__wrapper__item__info__box__job__demand')
a3.append(b1[i].text) #这里原来是list格式用b1[i] 提取原格式
for i in range(180):
b1=bor.find_elements_by_class_name('contentpile__content__wrapper__item__info__box__welfare__item')
a4.append(b1[i].text)
a5=[]
for i in range(180):
b1=bor.find_elements_by_class_name('contentpile__content__wrapper__item__info__box__job__comdec__item')
a5.append(b1[i].text)
a6=a5[::2] #分割a5为a6和a7
a7=a5[1::2]
bb=DataFrame()
bb['工资']=a1
bb['公司']=a2
bb['要求']=a3
bb['公司性质']=a6
bb['规模']=a7
return bb
def page(n)
gg2=DataFrame()
for j in range(n):
try:
mm='https://sou.zhaopin.com/?p={}&jl=854&sf=0&st=0&kw=数据分析&kt=3'.format(j+1)
#print(aaaa)
df_page=wab(mm)
gg2=gg2.append(df_page,ignore_index=True)
except:
pass
return gg2
gg2.to_csv("E:\papapappapaap\西安数据.csv") #保存数据
gg2.to_csv("E:\papapappapaap\北京数据.csv")
一、爬虫from selenium import webdriverimport pandas as pdfrom pandas import DataFrameimport timebor= webdriver.Chrome()def wab(www): bor.get(www) a1=[] for i in range(90): ...