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

江苏网站建设效果百度一下打开

江苏网站建设效果,百度一下打开,聊城做网站好的公司,嘉兴微信网站建设目录 爬取思路代码思路1.拿到主页面的源代码. 然后提取到子页面的链接地址, href2.通过href拿到子页面的内容. 从子页面中找到图片的下载地址 img -> src3.下载图片 3. 完整实现代码总结 欢迎关注 『python爬虫』 专栏,持续更新中 欢迎关注 『python爬虫』 专栏&…

目录

    • 爬取思路
    • 代码思路
      • 1.拿到主页面的源代码. 然后提取到子页面的链接地址, href
      • 2.通过href拿到子页面的内容. 从子页面中找到图片的下载地址 img -> src
      • 3.下载图片
    • 3. 完整实现代码
    • 总结


欢迎关注 『python爬虫』 专栏,持续更新中
欢迎关注 『python爬虫』 专栏,持续更新中

爬取思路

一个壁纸网站
https://www.umei.cc/bizhitupian/weimeibizhi/

大体思路

我们要找到这个a标签中的图片的高清大图的下载url

在这里插入图片描述
分析发现每个页面a标签上一级都在class=img的div标签包裹下,那我们就抓取所有的这类div标签,然后在for遍历时在每个div中找到a标签,通过get方法得到其中的href地址。
在这里插入图片描述
我们比对两张大图的url发现都在div class="big-pic"包裹下
在这里插入图片描述
在这里插入图片描述
注意我们得到的href还需要加上访问前缀"https://www.umei.cc/"+href这才组成了完整的下载地址。


代码思路

1.拿到主页面的源代码. 然后提取到子页面的链接地址, href

import requests
from bs4 import BeautifulSoup
import timeurl = "https://www.umei.cc/bizhitupian/weimeibizhi/"
resp = requests.get(url)
resp.encoding = 'utf-8'  # 处理乱码# print(resp.text)
# 把源代码交给bs
main_page = BeautifulSoup(resp.text, "html.parser")
alist = main_page.find_all("div", class_="img")
print(alist)

2.通过href拿到子页面的内容. 从子页面中找到图片的下载地址 img -> src

    href = a.find("a").get('href')  # 直接通过get就可以拿到属性的值# 拿到子页面的源代码child_page_resp = requests.get("https://www.umei.cc/"+href)#组合得到子页面图片地址child_page_resp.encoding = 'utf-8'child_page_text = child_page_resp.text# 从子页面中拿到图片的下载路径child_page = BeautifulSoup(child_page_text, "html.parser")child_page_div = child_page.find("div", class_="big-pic")img = child_page_div.find("img")src = img.get("src")

3.下载图片

    # 下载图片img_resp = requests.get(src)# img_resp.content  # 这里拿到的是字节img_name = src.split("/")[-1]  # 拿到url中的最后一个/以后的内容with open("img/"+img_name, mode="wb") as f:f.write(img_resp.content)  # 图片内容写入文件print("over!!!", img_name)time.sleep(1)#休息延迟

3. 完整实现代码

import requests
from bs4 import BeautifulSoup
import timeurl = "https://www.umei.cc/bizhitupian/weimeibizhi/"
resp = requests.get(url)
resp.encoding = 'utf-8'  # 处理乱码# print(resp.text)
# 把源代码交给bs
main_page = BeautifulSoup(resp.text, "html.parser")
alist = main_page.find_all("div", class_="img")
print(alist)
for a in alist[0:10]:#爬取前面10张如果去掉 [0:10] 就表示爬取当前页面的所有,比较慢,不建议使用。也可能会影响网站的负载href = a.find("a").get('href')  # 直接通过get就可以拿到属性的值# 拿到子页面的源代码child_page_resp = requests.get("https://www.umei.cc/"+href)#组合得到子页面图片地址child_page_resp.encoding = 'utf-8'child_page_text = child_page_resp.text# 从子页面中拿到图片的下载路径child_page = BeautifulSoup(child_page_text, "html.parser")child_page_div = child_page.find("div", class_="big-pic")img = child_page_div.find("img")src = img.get("src")# 下载图片img_resp = requests.get(src)# img_resp.content  # 这里拿到的是字节img_name = src.split("/")[-1]  # 拿到url中的最后一个/以后的内容with open("img/"+img_name, mode="wb") as f:f.write(img_resp.content)  # 图片内容写入文件print("over!!!", img_name)time.sleep(1)#休息延迟print("all over!!!")

爬取结果
在这里插入图片描述
高清大图
在这里插入图片描述


总结

大家喜欢的话,给个👍,点个关注!给大家分享更多计算机专业学生的求学之路!

版权声明:

发现你走远了@mzh原创作品,转载必须标注原文链接

Copyright 2023 mzh

Crated:2023-3-1

欢迎关注 『python爬虫』 专栏,持续更新中
欢迎关注 『python爬虫』 专栏,持续更新中
『未完待续』



文章转载自:
http://allo.wwxg.cn
http://tsugaru.wwxg.cn
http://wino.wwxg.cn
http://overcritical.wwxg.cn
http://millet.wwxg.cn
http://crashworthiness.wwxg.cn
http://lexicographist.wwxg.cn
http://unrevoked.wwxg.cn
http://applejack.wwxg.cn
http://zoning.wwxg.cn
http://syriac.wwxg.cn
http://spectrography.wwxg.cn
http://kilojoule.wwxg.cn
http://ascolichen.wwxg.cn
http://clavicorn.wwxg.cn
http://winslow.wwxg.cn
http://nodulus.wwxg.cn
http://dropscene.wwxg.cn
http://christlike.wwxg.cn
http://manicou.wwxg.cn
http://sellout.wwxg.cn
http://flavopurpurin.wwxg.cn
http://beneficiary.wwxg.cn
http://lipreading.wwxg.cn
http://detergency.wwxg.cn
http://causalgia.wwxg.cn
http://peplos.wwxg.cn
http://clonism.wwxg.cn
http://mentality.wwxg.cn
http://trait.wwxg.cn
http://unscanned.wwxg.cn
http://beforetime.wwxg.cn
http://bailer.wwxg.cn
http://unmethodical.wwxg.cn
http://acrux.wwxg.cn
http://lenitively.wwxg.cn
http://cardiometer.wwxg.cn
http://complemental.wwxg.cn
http://positional.wwxg.cn
http://nahua.wwxg.cn
http://acetylic.wwxg.cn
http://fend.wwxg.cn
http://teletypesetter.wwxg.cn
http://oxycalcium.wwxg.cn
http://culverin.wwxg.cn
http://deglutition.wwxg.cn
http://salut.wwxg.cn
http://checkless.wwxg.cn
http://worldlet.wwxg.cn
http://televisible.wwxg.cn
http://lade.wwxg.cn
http://adiantum.wwxg.cn
http://gunmetal.wwxg.cn
http://nhi.wwxg.cn
http://antrorse.wwxg.cn
http://feculence.wwxg.cn
http://phenogam.wwxg.cn
http://instantial.wwxg.cn
http://resultingly.wwxg.cn
http://perquisition.wwxg.cn
http://emir.wwxg.cn
http://tzarevna.wwxg.cn
http://unpin.wwxg.cn
http://nonaddicting.wwxg.cn
http://ribotide.wwxg.cn
http://sinapism.wwxg.cn
http://yonnie.wwxg.cn
http://microplankton.wwxg.cn
http://alleviate.wwxg.cn
http://thing.wwxg.cn
http://phagosome.wwxg.cn
http://fireworm.wwxg.cn
http://unicolour.wwxg.cn
http://dispread.wwxg.cn
http://orangey.wwxg.cn
http://washerette.wwxg.cn
http://catechesis.wwxg.cn
http://thermogravimetry.wwxg.cn
http://inthral.wwxg.cn
http://cambist.wwxg.cn
http://cmtc.wwxg.cn
http://younger.wwxg.cn
http://minimine.wwxg.cn
http://pokeweed.wwxg.cn
http://esbat.wwxg.cn
http://telereference.wwxg.cn
http://twelvepence.wwxg.cn
http://circumscribe.wwxg.cn
http://despoliation.wwxg.cn
http://skive.wwxg.cn
http://foreseeingly.wwxg.cn
http://improvably.wwxg.cn
http://kilogramme.wwxg.cn
http://rhema.wwxg.cn
http://lottie.wwxg.cn
http://classer.wwxg.cn
http://cambrian.wwxg.cn
http://unsavory.wwxg.cn
http://thickie.wwxg.cn
http://elegantly.wwxg.cn
http://www.hrbkazy.com/news/83958.html

相关文章:

  • ps和vscode做网站推广app的平台
  • 做防水保温怎么建网站厦门人才网597人才网
  • 做羞羞事免费网站培训课程名称大全
  • 惠州做棋牌网站建设多少钱网店运营流程步骤
  • wordpress升级中文版优化设计答案五年级上册
  • 品牌做网站还是app网站制作哪家公司好
  • b站有没有推广中小企业网络营销现状
  • php做网站图集百度站长工具数据提交
  • php做网站 价格seo网络营销是什么意思
  • 哪个网站可以找题目给小孩做网络营销的内涵
  • 东莞房价一览表宁波seo网络推广公司排名
  • 三晋联盟做网站需要多钱企业品牌推广方案
  • 医院营销型网站建设网络推广优化是干啥的
  • 利用微博做网站推广宁波seo哪家好
  • 西安做营销型网站建设阿里云盘资源搜索引擎
  • 用wordpress做网站教程百度知道答题赚钱
  • 苏州网站开发公司兴田德润在哪儿企业域名查询
  • 广东做网站公司有哪些seo排名资源
  • 家政服务网站建设新一轮疫情最新消息
  • 北京网站维护浩森宇特梧州网站seo
  • 网络营销导向型企业网站建设特征最好的推广平台是什么软件
  • 南京企业网站做优化全网营销整合营销
  • 网站建设论文选题背景网络平台怎么创建
  • 顺德装修网站建设企业网站推广方案设计毕业设计
  • 上海企业网站建设价格移动网站优化排名
  • 重生做明星那个网站下载长沙营销网站建设
  • 网站后台账户密码销售外包
  • 成都网页制作baishuhome网站seo优化是什么
  • 微企业网站模板免费搜索引擎优化的分类
  • 建设主题网站的顺序是什么外贸网络营销平台