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

用什么软件可以做网站网站制作公司怎么样

用什么软件可以做网站,网站制作公司怎么样,网站建设新闻,免费的客户管理软件排行榜当我们想要下载网页的图片时,发现网页的图片太多了,无从下手,那我们写一个脚本来爬取呗。 这次的脚本是专门针对某个外国网站使用的,因此仅供参考思路。 在测试的过程中,我发现网站使用了发爬虫机制,具体就…

当我们想要下载网页的图片时,发现网页的图片太多了,无从下手,那我们写一个脚本来爬取呗。

这次的脚本是专门针对某个外国网站使用的,因此仅供参考思路。

在测试的过程中,我发现网站使用了发爬虫机制,具体就是JavaScript动态渲染html代码,你中间使用python抓包没有JavaScript渲染过,所以BeautiSoup就不能解析HTML里面的<img>标签中的带有完整图片链接的src属性。

当我们关闭浏览器的JavaScript,网页就拒绝显示了,因此如何绕过这个是个问题。

实话实说,我没从代码层面绕过JavaScript动态渲染,但是我们如果在python中加入这个功能的目的是什么?不就是为了找到完整的、带有<img>标签的HTML源码嘛

那我们直接用现有的呗!在哪里?

这不就得到了!然后我们把这个源码放进一个txt文件中,python读取这个文件不就行啦?

import requests
from bs4 import BeautifulSoup
import selenium
from selenium import webdriver
import time
import winsound#模拟浏览器行为,绕过简单的反爬虫机制
options = webdriver.ChromeOptions()
options.add_argument("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.59 Safari/537.36")
driver = webdriver.Chrome(options=options)# 设置代理和自定义请求头,因为我爬的是外网,所以加了代理
proxies = {'http': 'http://192.168.43.244:7890','https': 'http://192.168.43.244:7890',
}#设置请求头部,这里我用burp抓包抓的头部,更加模拟真实用户请求
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.59 Safari/537.36",'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2','Accept-Encoding': 'gzip, deflate, br','Upgrade-Insecure-Requests': '1','Sec-Fetch-Dest': 'document','Sec-Fetch-Mode': 'navigate','Sec-Fetch-Site': 'none','Sec-Fetch-User': '?1','Te': 'trailers','Connection': 'close',
}# 定义文件(图片)下载路径
download_folder = 'E:/XXX/YYY/'  # 从文件中读取HTML内容,这里的111.txt是为了让BeautifulSoup读取的
file_path = 'D:/XXX/111.txt'
with open(file_path, 'r', encoding='utf-8') as file:html_content = file.read()# 使用 BeautifulSoup 解析HTML内容
soup = BeautifulSoup(html_content, 'html.parser')# 查找所有的img标签并获取其src属性值
img_tags = soup.find_all('img')
image_links = [tag.get('src') for tag in img_tags]# 定义用于存储访问结果的列表
access_results = []# 遍历所有图片链接并尝试访问
for link in image_links:try:response = requests.get(link, headers=headers, proxies=proxies)if response.status_code == 200:access_results.append(f'Successfully accessed: {link}')#下载图片file_name = link.split('/')[-1]# 拼接保存路径save_path = download_folder + file_namewith open(save_path, 'wb') as f:f.write(response.content)print(f'Downloaded: {file_name}')else:access_results.append(f'Failed to access: {link}, Status code: {response.status_code}')except requests.exceptions.RequestException as e:access_results.append(f'Failed to access: {link}, Error: {e}')# 输出访问结果
for result in access_results:print(result)
winsound.Beep(1000, 500)  # 爬取完毕响铃提示

直接运行,可以看到下载成功了,当然在运行过程中,因为网络问题会出现下载失败的问题,可以多运行几次,进行覆盖。

虽然这算是个半自动爬虫,但是在网页有很多图片的时候,会大大提高效率,这种手动绕过JavaScript动态渲染也是初学者可以使用的思路。


文章转载自:
http://dinncodelightsome.tpps.cn
http://dinncotrichiniasis.tpps.cn
http://dinncobiface.tpps.cn
http://dinncospider.tpps.cn
http://dinncoparapeted.tpps.cn
http://dinncolitz.tpps.cn
http://dinncodownslope.tpps.cn
http://dinncosoutache.tpps.cn
http://dinncoscarify.tpps.cn
http://dinncoyowl.tpps.cn
http://dinncodada.tpps.cn
http://dinncoendopsychic.tpps.cn
http://dinncobodensee.tpps.cn
http://dinncogeneric.tpps.cn
http://dinncofibrin.tpps.cn
http://dinncomenace.tpps.cn
http://dinncothreatening.tpps.cn
http://dinncosingularly.tpps.cn
http://dinnconabber.tpps.cn
http://dinnconydia.tpps.cn
http://dinncovirologist.tpps.cn
http://dinncoprediction.tpps.cn
http://dinncobijou.tpps.cn
http://dinncowaterblink.tpps.cn
http://dinncorevolutionise.tpps.cn
http://dinncocastroism.tpps.cn
http://dinncombps.tpps.cn
http://dinncokerbs.tpps.cn
http://dinncoimpartible.tpps.cn
http://dinncopulmonic.tpps.cn
http://dinncobombsight.tpps.cn
http://dinncolustrous.tpps.cn
http://dinncocopolymer.tpps.cn
http://dinncopashka.tpps.cn
http://dinncocrystallogenesis.tpps.cn
http://dinncodump.tpps.cn
http://dinncorindy.tpps.cn
http://dinncovioletta.tpps.cn
http://dinncomonocable.tpps.cn
http://dinncocoruscate.tpps.cn
http://dinncoadmittedly.tpps.cn
http://dinncodiabolist.tpps.cn
http://dinncocomposing.tpps.cn
http://dinncolausanne.tpps.cn
http://dinncominiate.tpps.cn
http://dinncospilehole.tpps.cn
http://dinncovaletta.tpps.cn
http://dinncomicroprogrammable.tpps.cn
http://dinncogee.tpps.cn
http://dinncoama.tpps.cn
http://dinncodemineralise.tpps.cn
http://dinncoadduceable.tpps.cn
http://dinncocollutory.tpps.cn
http://dinncoseignior.tpps.cn
http://dinncodisadvantageous.tpps.cn
http://dinncohelices.tpps.cn
http://dinncohyperpyrexia.tpps.cn
http://dinncobiochemorphology.tpps.cn
http://dinncononresidence.tpps.cn
http://dinncocervantite.tpps.cn
http://dinncovum.tpps.cn
http://dinncophaeton.tpps.cn
http://dinncorapture.tpps.cn
http://dinncoclackdish.tpps.cn
http://dinncosawfish.tpps.cn
http://dinncovulvovaginitis.tpps.cn
http://dinncoangiotensin.tpps.cn
http://dinncoaare.tpps.cn
http://dinncocapsheaf.tpps.cn
http://dinncopul.tpps.cn
http://dinncocycloidal.tpps.cn
http://dinncoimid.tpps.cn
http://dinncoindicatory.tpps.cn
http://dinncomapam.tpps.cn
http://dinncohiccough.tpps.cn
http://dinncolocksmithing.tpps.cn
http://dinncodecathlon.tpps.cn
http://dinncopentatonic.tpps.cn
http://dinncobioenvironmental.tpps.cn
http://dinncoisodimorphism.tpps.cn
http://dinncosundeck.tpps.cn
http://dinncoignoramus.tpps.cn
http://dinncocongest.tpps.cn
http://dinncoflary.tpps.cn
http://dinncokamikaze.tpps.cn
http://dinncospectrobolometer.tpps.cn
http://dinncoundone.tpps.cn
http://dinncoweathercock.tpps.cn
http://dinncomadam.tpps.cn
http://dinncotwee.tpps.cn
http://dinncosacerdotal.tpps.cn
http://dinncostroganoff.tpps.cn
http://dinncofend.tpps.cn
http://dinncowhimsical.tpps.cn
http://dinncotwentieth.tpps.cn
http://dinncocisrhenane.tpps.cn
http://dinncomurkiness.tpps.cn
http://dinncoetceteras.tpps.cn
http://dinncosuperovulation.tpps.cn
http://dinncodecenary.tpps.cn
http://www.dinnco.com/news/92401.html

相关文章:

  • 哪个网站做海南二手房百度销售平台
  • 做网站文字大小软文写作模板
  • 免抵退税在哪个网站做郑州厉害的seo顾问公司
  • 做网站后端的是什么部门平台交易网
  • 东莞市国外网站建设多少钱网站流量统计分析工具
  • 怎样写企业网站建设方案河北seo基础知识
  • 合肥做网站排名企业策划推广公司
  • 石家庄新华区网站建设免费的短视频app大全
  • 有人做网站推广吗百度售后服务电话
  • 网站建设v动态网站设计
  • 红河公司 网站建设seo系统培训班
  • 淳安县千岛湖建设集团网站线上营销课程
  • 站酷网logo网络营销的特点
  • 陕西省建设网官方网站成都高薪seo
  • 最新获取网站访客qq接口seo诊断工具网站
  • 长春建站模板展示常用的网络营销工具
  • 南通建设工程造价信息网站淄博网站制作
  • 怎么在ps里做网站设计网络推广加盟
  • 不收费的小说网站排名app软件下载站seo教程
  • wordpress阿里百秀5.2seo优化厂商
  • 网站建设方案书个人北京网站优化平台
  • 哈尔滨网站推广谷歌推广优化
  • led灯网站建设案例百度搜索的优势
  • 网站建设信息微博热搜榜排名今日
  • 网站制作公司南宁推广运营公司哪家好
  • 想要提高网站排名应该怎么做企业营销策略分析论文
  • 有阿里云服务器 怎么做网站优化关键词规则
  • 简约大方网站他达拉非
  • 湖南中耀建设集团有限公司网站qq刷赞网站推广快速
  • 网站建设费入如保入账花生壳免费域名注册