本篇仅在于交流学习

解析页面

可以采用xpath进行页面连接提取

进入页面

通过进入的页面可以得到下载地址

步骤:

提取表页面模板链接——>进入连接——>提取页面内下载地址连接——>下载保存

headers = {
'User-Agent': '用自己得头部'
}
response = requests.get(url=url, headers=headers).text #解析页面
tree = etree.HTML(response)
#print(tree)
page_list = tree.xpath('//div[@id="main"]/div/div/a') #捕获信息位置
for li in page_list:
page_list_url = li.xpath('./@href')[0]
page_list_url = 'https:' + page_list_url #提取页面地址
#print(page_list_url)
in_page = requests.get(url=page_list_url,headers=headers).text #进入地址
trees = etree.HTML(in_page)
#print(trees)
download_url = trees.xpath('//div[@class="clearfix mt20 downlist"]/ul/li/a/@href')[0] #目的文件地址
name = trees.xpath('//div[@class="ppt_tit clearfix"]/h1/text()')[0] + '.rar' #文件名字
name = name.encode('iso-8859-1').decode('utf-8') #修改命名乱码
#print(download_url)
if not os.path.exists('./download'): #保存
os.mkdir('./download')
download = requests.get(url=download_url,headers=headers).content
page_name = 'download/' + name
with open(page_name,'wb') as fp:
fp.write(download)
print(name,'end!')

  

分析网页之间联系:

实施多页面提取

    try:
start = int(input('请输入要爬取到的尾页:'))
if start == 1 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
print("爬取完毕")
elif start == 2 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
url = 'https://sc.chinaz.com/jianli/free_2.html'
get_page(url)
print("爬取完毕")
elif start >= 3 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
for i in range(2, start):
url = 'https://sc.chinaz.com/jianli/free_%s.html' % (i * 1)
get_page(url)
print("爬取完毕")
except ValueError:
print('请输入数字:')

  

完整代码:

import requests
from lxml import etree
import os
def get_page(url):
headers = {
'User-Agent': '自己的头部'
}
response = requests.get(url=url, headers=headers).text #解析页面
tree = etree.HTML(response)
#print(tree)
page_list = tree.xpath('//div[@id="main"]/div/div/a') #捕获信息位置
for li in page_list:
page_list_url = li.xpath('./@href')[0]
page_list_url = 'https:' + page_list_url #提取页面地址
#print(page_list_url)
in_page = requests.get(url=page_list_url,headers=headers).text #进入地址
trees = etree.HTML(in_page)
#print(trees)
download_url = trees.xpath('//div[@class="clearfix mt20 downlist"]/ul/li/a/@href')[0] #目的文件地址
name = trees.xpath('//div[@class="ppt_tit clearfix"]/h1/text()')[0] + '.rar' #文件名字
name = name.encode('iso-8859-1').decode('utf-8') #修改命名乱码
#print(download_url)
if not os.path.exists('./download'): #保存
os.mkdir('./download')
download = requests.get(url=download_url,headers=headers).content
page_name = 'download/' + name
with open(page_name,'wb') as fp:
fp.write(download)
print(name,'end!')
def go(): #多页面选择
try:
start = int(input('请输入要爬取到的尾页:'))
if start == 1 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
print("爬取完毕")
elif start == 2 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
url = 'https://sc.chinaz.com/jianli/free_2.html'
get_page(url)
print("爬取完毕")
elif start >= 3 :
url = 'https://sc.chinaz.com/jianli/free.html'
get_page(url)
for i in range(2, start):
url = 'https://sc.chinaz.com/jianli/free_%s.html' % (i * 1)
get_page(url)
print("爬取完毕")
except ValueError:
print('请输入数字:')
go() if __name__ == '__main__':
go()

  

效果:

【python爬虫】对站长网址中免费简历模板进行爬取的更多相关文章

  1. Python爬虫入门教程 15-100 石家庄政民互动数据爬取

    石家庄政民互动数据爬取-写在前面 今天,咱抓取一个网站,这个网站呢,涉及的内容就是 网友留言和回复,特别简单,但是网站是gov的.网址为 http://www.sjz.gov.cn/col/14900 ...

  2. Python爬虫入门教程第七讲: 蜂鸟网图片爬取之二

    蜂鸟网图片--简介 今天玩点新鲜的,使用一个新库 aiohttp ,利用它提高咱爬虫的爬取速度. 安装模块常规套路 pip install aiohttp 运行之后等待,安装完毕,想要深造,那么官方文 ...

  3. Python爬虫实践~BeautifulSoup+urllib+Flask实现静态网页的爬取

    爬取的网站类型: 论坛类网站类型 涉及主要的第三方模块: BeautifulSoup:解析.遍历页面 urllib:处理URL请求 Flask:简易的WEB框架 介绍: 本次主要使用urllib获取网 ...

  4. Java分布式爬虫Nutch教程——导入Nutch工程,执行完整爬取

    Java分布式爬虫Nutch教程--导入Nutch工程,执行完整爬取 by briefcopy · Published 2016年4月25日 · Updated 2016年12月11日 在使用本教程之 ...

  5. Python中使用requests和parsel爬取喜马拉雅电台音频

    场景 喜马拉雅电台: https://www.ximalaya.com/ 找到一步小说音频,这里以下面为例 https://www.ximalaya.com/youshengshu/16411402/ ...

  6. Python爬虫:新浪新闻详情页的数据抓取(函数版)

    上一篇文章<Python爬虫:抓取新浪新闻数据>详细解说了如何抓取新浪新闻详情页的相关数据,但代码的构建不利于后续扩展,每次抓取新的详情页时都需要重新写一遍,因此,我们需要将其整理成函数, ...

  7. python应用:爬虫框架Scrapy系统学习第四篇——scrapy爬取笔趣阁小说

    使用cmd创建一个scrapy项目: scrapy startproject project_name (project_name 必须以字母开头,只能包含字母.数字以及下划线<undersco ...

  8. Python 网络爬虫 006 (编程) 解决下载(或叫:爬取)到的网页乱码问题

    解决下载(或叫:爬取)到的网页乱码问题 使用的系统:Windows 10 64位 Python 语言版本:Python 2.7.10 V 使用的编程 Python 的集成开发环境:PyCharm 20 ...

  9. Python爬虫学习==>第十一章:分析Ajax请求-抓取今日头条信息

    学习目的: 解决AJAX请求的爬虫,网页解析库的学习,MongoDB的简单应用 正式步骤 Step1:流程分析 抓取单页内容:利用requests请求目标站点,得到单个页面的html代码,返回结果: ...

  10. python网络爬虫(12)去哪网酒店信息爬取

    目的意义 爬取某地的酒店价格信息,示例使用selenium在Firefox中的使用. 来源 少部分来源于书.python爬虫开发与项目实战 构造 本次使用简易的方案,模拟浏览器访问,然后输入字段,查找 ...

随机推荐

  1. Must be called at the top of a `setup` function vue3使用vue-i18n时出现的报错

    在某js文件中引入 import {useI18n} from "vue-i18n"; 使用:useI18n().t('APP_LOADING') 修改后: import i18n ...

  2. sql自学记录

    复习 SQL join :用于根据两个或多个表中的列之间的关系,从这些表中查询数据 eg: SELECT Persons.LastName, Persons.FirstName, Orders.Ord ...

  3. 转载C#加密方法

    方法一:    //须添加对System.Web的引用     using System.Web.Security;          ...          /// <summary> ...

  4. 如何优化if--else

    1.现状代码 public interface IPay { void pay(); } package com.test.zyj.note.service.impl; import com.test ...

  5. cider 二面

    cider 二面 1.祖传自我介绍 2.当前BLF外卖业务缺点是什么? 产品单一 : 跟竞品比较起来,产品单一导致用户流量很少 3.QLExpress二次开发的原因 流程对接 提升性能 后台对接 4. ...

  6. database.property文件

    注意修改用户名密码 mysql8的版本要注意配置时区 此文件放置连接数据库的相关参数 jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://l ...

  7. binder机制分析

    1. binder基本概念 1.1 特点 1)binder 是一种基于C/S通信模式的IPC(Inter_Process Communication). 2)在传输过程中近需要一次copy,为发送添加 ...

  8. 【打怪升级】【rocketMq】rocket的持久化

    rocket持久化保证的思想有两点:1是刷盘保证大部分数据不丢失:2是持久化文件的处理,零拷贝技术和内存页,NIO模型保证处理能力 文件持久化目录 ├──abort:rocket broker启动检查 ...

  9. mybatis-plus 开发环境在控制台打印日志

    参考博客:https://blog.csdn.net/qq_32929057/article/details/109291919 # 注意在生产环境注释掉 mubatis-plus: configur ...

  10. Typora怎么插入行内公式?内联公式设置

    文件 偏好设置 把内联公式那个勾上就可以了.然后就能写latex了,像这样,$\alpha\$ \(\alpha\) 输入一个\$后再按esc,会自动补全为$$