批量下载简历模板

源代码

import requests
import os
from lxml import etree

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                  'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
}

if not os.path.exists('resume_template'):
    os.mkdir('resume_template')


url_cnt = download_cnt = 0
template_url_list = []
template_name = []
download_url_list = []

url = 'http://sc.chinaz.com/jianli/free_%d.html'
for i in range(1, 6):
    if i == 1:
        entrance_url = 'http://sc.chinaz.com/jianli/free.html'
    else:
        entrance_url = format(url % i)
    entrance_page = requests.get(url=entrance_url, headers=headers)
    entrance_page.encoding='utf-8'
    tree = etree.HTML(entrance_page.text)
    entrance_list = tree.xpath('//div[@id="main"]//p/a')

    for item in entrance_list:
        name = item.xpath('./text()')[0]
        addr = item.xpath('./@href')[0]
        # print(title)
        # print(addr)
        template_url_list.append(addr)
        template_name.append(name)
        url_cnt += 1

print(url_cnt)
for i in range(len(template_url_list)):
    template_url = template_url_list[i]
    print(template_url)
    template_page = requests.get(url=template_url, headers=headers).text
    tree = etree.HTML(template_page)
    download_url = tree.xpath('//div[@class="down_wrap"]//ul/li[10]/a/@href')[0]

    path = './resume_template/' + template_name[i]
    # if not os.path.exists(path):
    #     os.mkdir(path)
    #     print("make")

    template = requests.get(url=download_url, headers=headers).content
    # z = zipfile.ZipFile(io.BytesIO(template))
    # z.extractall(path)


    with open(path + '.rar', 'wb') as f:
        f.write(template)
        download_cnt += 1
    download_url_list.append(download_url)

print(download_cnt)


  • 第一, xpath的语法不太熟练

    这个xpath其实语法挺简单的,只要系统地去了解一下就行,搞清楚相应符号的意义基本就问题不大

  • 第二, 当url对应的下载文件是zip文件时,不知道该以何种方式下载能让下载下来的直接就是压缩文件,后来是参考了 python爬虫爬取站长素材免费简历模板完成的。

运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="ResumeDB" connectionString="Data Source=192.168.1.240;Initial Catalog=ResumeImport;User ID=ResumeImport;Password=ResumeImport2012" providerName="System.Data.SqlClient" /> <!--<add name="ResumeDB" connectionString="Server=DEV2-PC\RICHARD;Database=Resume;Trusted_Connection=True;" />--> </connectionStrings> <appSettings> <!--导入数据源 DB表示是去数据库取数 Directory表示直接从文件夹下导入 Excel表示数据源为Excel--> <add key="ImportSource" value="Directory"/> <!--<add key="UserName" value="baza_TZDZ"/> <add key="PWD" value="12a6eafd1a616e11ce51e419ab1435"/>--> <add key="UserName" value="baza_SZSQHD"/> <add key="PWD" value="52f6eafd9a616e94cd10e419db7818"/> <!--文件大小限制 单位KB--> <add key="LimitSize" value="2000"/> <!--支持上传的文件类型--> <!--<add key="PermitImportFileExtension" value="doc,pdf,txt,html,htm"/>--> <add key="PermitImportFileExtension" value="doc,pdf,txt,html,htm,mht"/> <!--简历的渠道 1:招聘网站,2:猎头招聘,3:员工推荐,4:现场招聘,5:校园招聘,6:媒体广告,7:官网,8:企业人才库,9:其它, 10131:领导推荐,10132:外包,10133:培训机构,10254:职酷 如果不填或填0,则默认使用企业人才库--> <add key="Channel" value="0"/> <!--以下是数据源为Directory的参数 begin--> <add key="FileDirectory" value="F:\中国人才热线下载简历"/> <add key="CurrentlyFilePath" value=""/> <!--以上是数据源为Directory的参数 end--> <!--编码格式 int型 65001为UTF-8 936为默认--> <add key="CodePage" value="936"/> <!--以下是数据源为DB的参数 begin--> <add key="ServiceAddress" value=""/> <add key="TempDirectory" value="d:\ResumeTemp"/> <add key="FileStartID" value="0"/> <add key="FileIDName" value="ReportID"/> <add key="FileDataName" value="WordContent"/> <add key="FileTypeName" value="docname"/> <add key="GetResumeSql" value="select top 50 {0},WordContent,docname from ResumeDocReportTable where {0} > {1} order by {0} "/> <add key="WaitTime" value="10"/> <!--是否保存文件,0表示不保存,1表示保存导入错误的文件,2都保存--> <add key="SaveFile" value="1"/> <add key="FileExtension" value="doc"/> <!--以上是数据源为DB的参数 end--> <!--以下是数据源为Excel的参数 begin--> <add key="ExcelFileDirectory" value="C:\Documents and Settings\kiki\桌面\简历导入工具"/> <add key="ExcelToTxtTemplate" value="C:\Documents and Settings\kiki\桌面\简历导入工具\Template\ExcelToTxtTemplate.txt"/> <add key="ExcelRowKey" value="姓名"/> <add key="ExistKeyCount" value="3"/> <add key="CurrentlyExcelFilePath" value=""/> <!--以上是数据源为Excel的参数 end--> </appSettings> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IResumeImport" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="3200" maxStringContentLength="819200" maxArrayLength="1638400" maxBytesPerRead="409600" maxNameTableCharCount="1638400" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://115.29.222.109:8008/Baza.Hirede.Services.ResumeImport.ResumeImportService.svc/ResumeImport" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IResumeImport" contract="ResumeImportService.IResumeImport" name="BasicHttpBinding_IResumeImport" /> </client> </system.serviceModel> </configuration> <!--http://weixun.hirede.com/Baza.Hirede.Services.ResumeImport.ResumeImportService.svc/ResumeImport--> <!--http://localhost:8410/ResumeImport--> <!--http://resumeimport.hirede.com/Baza.Hirede.Services.ResumeImport.ResumeImportService.svc-->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值