import urllib,re,xlwt;
def get_content():
url = 'https://search.51job.com/list/000000,000000,0000,00,9,99,python,2,1.html?lang=c&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=';
a = urllib.request.urlopen(url);
html = a.read();
html = html.decode('gbk');
#print(html);
return html;
def get():
html = get_content();
reg = re.compile(r'class="t1 ">.*?<a target="_blank" title="(.*?)".*?<span class="t2"><a target="_blank" title="(.*?)".*?<span class="t3">(.*?)</span>.*?<span class="t4">(.*?)</span>.*?<span class="t5">(.*?)</span>',re.S)
items = re.findall(reg,html);
#print(items);
#print(items[0][0]);
return items;
def write_excel(items):
newtable = 'text.xls';
wb = xlwt.Workbook(encoding = 'utf-8');
ws = wb.add_sheet('text1');
title = ['职位名','公司名','工作地点','薪资','发布时间'];
for i in range(0,5):
ws.write(0,i,title[i]);
index = 1;
for item in items:
for i in range(0,5):
ws.write(index,i,item[i]);
index+=1;
wb.save(newtable);
if __name__ == '__main__':
items = get();
write_excel(items);
爬虫
最新推荐文章于 2024-04-01 13:30:49 发布