您的位置:首页 > 编程语言 > Python开发

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

2018-03-22 22:49 525 查看
# _*_ 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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  th