代码拉取完成,页面将自动刷新
import re
import requests
from bs4 import BeautifulSoup
import csv
f=open('gangwei.csv','w',newline='')
csvwriter=csv.writer(f)
for i in range(1,11):
print(f"正在爬取都{i}页")
url=f'https://www.qlrc.com/personal/js/search?keywords=%E6%95%B0%E6%8D%AE'
header={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36'
}
# header_dict = dict(header)
res=requests.get(url,headers=header)
res.encoding=res.apparent_encoding
html=res.text
soup=BeautifulSoup(html,'html.parser')
gangweis=soup.find_all('div',attrs={'class':'jobname'})
requires=soup.find_all('div',attrs={'class':'jobrequire'})
# print(gangweis)
gangWeiXinXi=[]
for i in range(len(gangweis)):
xinXi=[]
gangwei=gangweis[i].a.text.strip()
# print(gangwei)
xinXi.append(gangwei)
lianjie='https://www.qlrc.com/'+gangweis[i].a['href']
xinXi.append(lianjie)
require=requires[i].children
for j in require:
text=j.text.replace(' ','')
# print(text)
if len(text)>0:
xinXi.append(text)
gangWeiXinXi.append(xinXi)
for i in range(len(gangWeiXinXi)):
url1=gangWeiXinXi[i][1]
res1=requests.get(url1,headers=header)
res.encoding=res1.apparent_encoding
html1=res1.text
obj=re.compile(r'<p class="text-content" data-v-\w{8}>(?P<gangweijieshao>.*?)</p>')
result1 = obj.finditer(html1)
for item1 in result1:
gangWeiXinXi[i].append(item1.group('gangweijieshao'))
# print(url1)
for info in gangWeiXinXi:
gangwei_name=info[0]
gangwei_lianjie=info[1]
gangwei_xinzi=info[2]
gangwei_dizhi=info[3]
gangwei_nianxin=info[4]
gangwei_xueli=info[5]
gangwei_zhize=info[6]
gangwei_yaoqiu=info[7]
csvwriter.writerow(
["岗位名称", "gangwei_lianjie", "gangwei_xinzi", "gangwei_dizhi", "gangwei_nianxin", "gangwei_xueli", "gangwei_zhize",
"gangwei_yaoqiu"])
csvwriter.writerow([gangwei_name,gangwei_lianjie,gangwei_xinzi,gangwei_dizhi,gangwei_nianxin,gangwei_xueli,gangwei_zhize,gangwei_yaoqiu])
f.close()
# print(gangWeiXinXi)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。