|
- import re
- import requests
- import csv
- import time
- def request_pares(page):
- url = f'https://search.51job.com/list/010000,000000,0000,00,9,99,%25E5%25A4%25A7%25E6%2595%25B0%25E6%258D%25AE,2,{page}.html'
- #请求
- resp**e = requests.get(url=url, headers=headers)
- #解析提取
- job_name_list = re.findall('"job_name":"(.*?)","job_title":"', resp**e.text)
- company_name_list = re.findall('"company_name":"(.*?)","providesalary_text"', resp**e.text)
- salary_list = re.findall('"providesalary_text":"(.*?)","workarea"', resp**e.text)
- time.sleep(1)
- print(f'正在解析下载第(page)页招聘信息。。。。。。')
- download_save_csv(job_name_list,company_name_list,salary_list)
- def download_save_csv(job_name_list,company_name_list,salary_list):
- for i in range(len(job_name_list)):
- data = [job_name_list[i], company_name_list[i], salary_list[i].replace('\/', '/')]
- with open('./data/职位信息.csv','a',encoding='utf-8',newline='') as f:
- writer = csv.writer(f)
- writer.writerow(data)
- if __name__ == "__main__":
- with open('./data/职位信息.csv','w',encoding='utf-8',newline='') as f:
- writer = csv.writer(f)
- writer.writerow(['职位','公司名称 ','薪资'])
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'
- }
- for page in range(1,21):
- request_pares(page)
复制代码 运行时出现如下错误:
File "C:\Users\Administrator\Desktop\正则表达式练习之爬取网站多页信息.py", line 27, in <module>
with open('./data/职位信息.csv','w',encoding='utf-8',newline='') as f:
FileNotFoundError: [Errno 2] No such file or directory: './data/职位信息.csv'
有路过的大神帮忙分析一下吗?
我知道答案
回答被采纳将会获得 10 C币 已有1人回答
|
|