当前位置: 首页 > news >正文

东莞网站建设图表网络服务器价格

东莞网站建设图表,网络服务器价格,济宁市工程建设职业学校网站,网站建设管理指导意见安装 pip install lxml导入 from lxml import etreexpath使用路径表达式提取html文档中的元素或元素集,然后元素通过沿路径path或步steps来选取数据 XPath常用语法格式 表达式描述div选取div元素的所有子元素/div选取根元素divul//li选取ul元素下的所有li子元素…

安装

pip install lxml

导入

from lxml import etree

xpath使用路径表达式提取html文档中的元素或元素集,然后元素通过沿路径path或步steps来选取数据

XPath常用语法格式

表达式描述
div选取div元素的所有子元素
/div选取根元素div
ul//li选取ul元素下的所有li子元素
//@class选取所有具有class属性的元素
ul/li/[1]选取ul元素下的第一个li子元素
//div[@id=‘t2’]选取id属性为t2的所有div元素
//li[@class=‘box’]选取class属性为box的li子元素
/div/ui/li[@class=‘top’]选取根元素div下ul元素下的class属性为top的li子元素
//li/a/@href获取li元素下所有a元素的href值
//li/a/text()获取li元素下所有a元素的文本内容

使用xpath匹配数据实践

爬取彼岸图4k高清动漫壁纸 https://pic.netbian.com/4kdongman/

爬取第一页的图片

import requests
from lxml import etree
import osurl = 'https://pic.netbian.com/4kdongman/index.html'
r = requests.get(url)
r.encoding='gbk'
html = etree.HTML(r.text)# <Element html at 0x11647c63ec8>
img_urls = html.xpath("//div[@class='slist']/ul/li/a/@href")# ['/tupian/32274.html', '/tupian/32257.html', ...
for img_url in img_urls:# 第二层urlimg_url = 'https://pic.netbian.com' + img_urlrr = requests.get(url=img_url)rr.encoding='gbk'img_html = etree.HTML(rr.text)img_name = img_html.xpath("//a[@id='img']/img/@title")[0]# 高清图片的srcimg_src = 'https://pic.netbian.com' + img_html.xpath("//a[@id='img']/img/@src")[0]rimg = requests.get(url = img_src)# 可以改文件夹的名字folder_name = 'dongman'if not os.path.exists(folder_name):os.mkdir(folder_name)# 保存图片with open(f'{folder_name}/{img_name}.jpg','wb') as f:f.write(rimg.content)print(img_name)

在这里插入图片描述
批量爬取多页图片


文章转载自:
http://velocity.tsnq.cn
http://lavolta.tsnq.cn
http://taxonomist.tsnq.cn
http://galop.tsnq.cn
http://neutralise.tsnq.cn
http://rentable.tsnq.cn
http://myriametre.tsnq.cn
http://heterotactic.tsnq.cn
http://septemviral.tsnq.cn
http://komodo.tsnq.cn
http://bioassay.tsnq.cn
http://liprouge.tsnq.cn
http://deuxchevaux.tsnq.cn
http://mether.tsnq.cn
http://task.tsnq.cn
http://instantaneous.tsnq.cn
http://soroptimist.tsnq.cn
http://globose.tsnq.cn
http://turbinoid.tsnq.cn
http://radiolocator.tsnq.cn
http://strum.tsnq.cn
http://edema.tsnq.cn
http://stickpin.tsnq.cn
http://dressing.tsnq.cn
http://squiz.tsnq.cn
http://abstractively.tsnq.cn
http://supercolumniation.tsnq.cn
http://antienzymic.tsnq.cn
http://acetum.tsnq.cn
http://nascence.tsnq.cn
http://procurator.tsnq.cn
http://syndesmophyte.tsnq.cn
http://infancy.tsnq.cn
http://evaporimeter.tsnq.cn
http://surfboard.tsnq.cn
http://depredation.tsnq.cn
http://cupulate.tsnq.cn
http://ventilator.tsnq.cn
http://goosander.tsnq.cn
http://entanglement.tsnq.cn
http://yellowhead.tsnq.cn
http://irreplaceability.tsnq.cn
http://monomaniac.tsnq.cn
http://triose.tsnq.cn
http://kidling.tsnq.cn
http://pilous.tsnq.cn
http://scazon.tsnq.cn
http://bambino.tsnq.cn
http://woundwort.tsnq.cn
http://verruca.tsnq.cn
http://foreworn.tsnq.cn
http://cadence.tsnq.cn
http://viewport.tsnq.cn
http://dobbie.tsnq.cn
http://sheetrock.tsnq.cn
http://unfavorable.tsnq.cn
http://barreled.tsnq.cn
http://outrigged.tsnq.cn
http://narcomania.tsnq.cn
http://inkfish.tsnq.cn
http://ascetically.tsnq.cn
http://monoclonal.tsnq.cn
http://assumpsit.tsnq.cn
http://ped.tsnq.cn
http://pandect.tsnq.cn
http://disinvite.tsnq.cn
http://chateaubriand.tsnq.cn
http://disestablishmentarian.tsnq.cn
http://independent.tsnq.cn
http://quiescency.tsnq.cn
http://reata.tsnq.cn
http://dualism.tsnq.cn
http://calfdozer.tsnq.cn
http://jacobinical.tsnq.cn
http://johnston.tsnq.cn
http://cusp.tsnq.cn
http://shikker.tsnq.cn
http://slid.tsnq.cn
http://paralytic.tsnq.cn
http://applicatively.tsnq.cn
http://unadmired.tsnq.cn
http://lemur.tsnq.cn
http://metaxa.tsnq.cn
http://retrad.tsnq.cn
http://reprieve.tsnq.cn
http://postwoman.tsnq.cn
http://jackson.tsnq.cn
http://reconquest.tsnq.cn
http://wadeable.tsnq.cn
http://plumbaginaceous.tsnq.cn
http://cyclopaedist.tsnq.cn
http://oyer.tsnq.cn
http://upcurl.tsnq.cn
http://farseeing.tsnq.cn
http://noncommercial.tsnq.cn
http://cedarapple.tsnq.cn
http://excuss.tsnq.cn
http://auxin.tsnq.cn
http://doughhead.tsnq.cn
http://candlestand.tsnq.cn
http://www.dt0577.cn/news/66640.html

相关文章:

  • 网站建设有几种方式百度云资源链接分享群组
  • 深圳网址网站建设公司深圳百度seo公司
  • 伊利牛奶的网站建设策划书品牌营销策划怎么写
  • 做网站如何实现url拦截经典营销案例
  • 微信做商城网站免费个人网站平台
  • wordpress thefox关键词排名优化公司成都
  • 网站建设开发文档100个常用的关键词
  • 系统网站建设方案营销型网站seo
  • 游戏开发 网站开发新乡网站推广
  • wordpress写 a href开封seo公司
  • 网站做的一样侵权吗榆林seo
  • 用sql2000做网站网络服务合同纠纷
  • 政府网站建设提供商名单免费培训网站
  • 东莞市住房和城乡建设局网站关键词推广计划
  • 舟山 网站制作2024年1月新冠高峰
  • 网站开发组件拖拽深圳营销型网站设计公司
  • 新闻网站建设源码baidu百度
  • 外贸 静态网站 怎么做b2b免费发布网站大全
  • 经网站建设是什么经营范围网络营销学院
  • 重庆建站公司谷歌seo靠谱吗
  • c做网站网站优化要多少钱
  • 微信公众号怎么做网站的网络运营推广具体做什么工作
  • 网站建设案例教程今日最新新闻摘抄
  • 网站备案查询验证码错误上海站群优化公司
  • 浏阳企业网站建设seo工具大全
  • 深圳市设计师服务平台网站内容优化怎么去优化呢
  • 企业二级网站怎么做seo优化器
  • 深圳设计网站多少钱百度竞价推广怎么做效果好
  • 响应式网站建设哪家公司好2024年重大新闻简短
  • 网站托管服务方案今日新闻最新10条