Python爬取招聘信息并保存到本地

# _*_ coding:utf-8 _*_
import requests
from bs4 import BeautifulSoup as bs
import re
import os
def getJobInfo(url):
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
r = requests.get(url,headers=headers).content
soup=bs(r,'html.parser')
for item in soup.find_all('li',class_='job_item clearfix'):
f.write(str(item.get_text(' ')))
f.write(str((item.a.get('href'))))
f.write('\n')
#job_style=['renli','zpshengchan','tech','zpjixieyiqi','zhuanye']
#city=['bj','sh','sz','gz']
i=1
f=open('北京教育招聘.txt','w',encoding='utf-8')
while i<71:
url='http://bj.58.com/zhuanye/pn%d' %i
i=i+1
getJobInfo(url)
f.close()

你可能感兴趣的:(python)