网站地图    收藏   

主页 > 后端 > python >

python 爬取免费简历模板网站的示例

来源:自学PHP网    时间:2020-09-28 10:17 作者:小飞侠 阅读:

[导读] python 爬取免费简历模板网站的示例...

今天带来python 爬取免费简历模板网站的示例教程详解

代码

# 免费的简历模板进行爬取本地保存 
# http://sc.chinaz.com/jianli/free.html
# http://sc.chinaz.com/jianli/free_2.html

import requests
from lxml import etree
import os

dirName = './resumeLibs'
if not os.path.exists(dirName):
  os.mkdir(dirName)

headers = {
  'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
}
url = 'http://sc.chinaz.com/jianli/free_%d.html'
for page in range(1,2):
  if page == 1:
    new_url = 'http://sc.chinaz.com/jianli/free.html'
  else:
    new_url = format(url%page)
  page_text = requests.get(url=new_url,headers=headers).text
  tree = etree.HTML(page_text)
  a_list = tree.xpath('//div[@id="container"]/div/p/a')
  
  for a in a_list:
    a_src = a.xpath('./@href')[0]
    a_title = a.xpath('./text()')[0]
    a_title = a_title.encode('iso-8859-1').decode('utf-8')
    # 爬取下载页面
    page_text = requests.get(url=a_src,headers=headers).text
    tree = etree.HTML(page_text)
    dl_src = tree.xpath('//div[@id="down"]/div[2]/ul/li[8]/a/@href')[0]
    
    resume_data = requests.get(url=dl_src,headers=headers).content
    resume_name = a_title
    resume_path = dirName + '/' + resume_name + '.rar'
    with open(resume_path,'wb') as fp:
      fp.write(resume_data)
      print(resume_name,'下载成功!')

爬取结果


以上就是关于python 爬取免费简历模板网站的示例全部内容,感谢大家支持自学php网。

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论