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

域名校验?反爬界的掩耳盗铃!

这一集我们讲一个比较简单的域名校验,可能你没有听过这个名字,因为这个名字是我编的,那么它究竟是什么呢?又为什么说它是掩耳盗铃呢?我们来看看下面的案例:

  1. 必应搜索页隐藏内容
  2. 虎嗅新闻跳转404
import requests
import chardet
from bs4 import BeautifulSoup,Commentdef remove_css(html):soup = BeautifulSoup(html, 'html.parser')# print(soup.text)# 删除<style>标签# for style_tag in soup('style'):#     style_tag.decompose()# 删除<link>标签# for link_tag in soup('link'):#     link_tag.decompose()# 删除<symbol>标签for symbol_tag in soup('symbol'):symbol_tag.decompose()# 删除<script>标签for script_tag in soup('script'):script_tag.decompose()# 删除<svg>标签for script_tag in soup('svg'):script_tag.decompose()# 删除注释comments = soup.find_all(string=lambda text: isinstance(text, Comment))for comment in comments:comment.extract()return str(soup)def download_page(url,file_name):headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'}r = requests.get(url=url, headers=headers)encoding = chardet.detect(r.content)["encoding"]if encoding.lower() == "gb2312":encoding = 'gb18030'html = r.content.decode(encoding)with open(file_name,'w',encoding='utf-8') as f:f.write(html)# f.write(remove_css(html))url = 'https://cn.bing.com/search?q=%E5%AE%A4%E6%B8%A9%E8%B6%85%E5%AF%BC&form=QBLH&sp=-1&lq=0&pq=%E5%AE%A4%E6%B8%A9%E8%B6%85%E5%AF%BC&sc=10-4&qs=n&sk=&cvid=DA87FC09FB9F4425908E34195B622973&ghsh=0&ghacc=0&ghpl='
download_page(url=url,file_name='1.biying.html')
url = 'https://www.huxiu.com/article/1870796.html'
download_page(url=url,file_name='2.huxiu.html')

这两个页面获取到之后都无法正常显示,需要去掉请求到的页面里的js代码,就正常了

为什么说有掩耳盗铃的嫌疑呢?因为数据是真正获取到的,只是不给看到。

视频教程地址:https://www.bilibili.com/video/BV1RN411h78z/

http://www.lryc.cn/news/109627.html

相关文章:

  • Cesium 实战教程 - 调整 3dtiles 倾斜摄影大小
  • python机器学习(七)决策树(下) 特征工程、字典特征、文本特征、决策树算法API、可视化、解决回归问题
  • 数据结构与算法中的双向链表
  • 数据安全治理的关键-数据分类分级工具
  • Spring集成Junit
  • Java正则校验密码至少包含:字母数字特殊符号中的2种
  • Stable Diffusion教程(6) - 扩展安装
  • Jenkins通过OpenSSH发布WinServer2016
  • 字母异位词分组 LeetCode热题100
  • 使用angular和electron 构建桌面应用
  • 安达发制造工业迈向智能化:APS高级计划排程助力提升生产效率
  • Flink - sink算子
  • 【项目 线程2】3.5 线程的分离 3.6线程取消 3.7线程属性
  • Filebeat+ELK 部署
  • el-table点击表格某一行添加到URL参数,访问带参URL加载表格内容并滚动到选中行位置 [Vue3] [Element-plus 2.3]
  • 【树】 二叉树 堆与堆排序 平衡(AVL)树 红黑(RB)树
  • 信号平滑或移动平均滤波研究(Matlab代码实现)
  • 黑客技术(网络安全)自学
  • 使用七牛云、阿里云、腾讯云的对象存储上传文件
  • 使用阿里云DataX完成数据同步
  • 《Kali渗透基础》13. 无线渗透(三)
  • python——案例六:判断字符串的长度
  • PC-windows-安卓-Linux音频系统框架概论
  • Web Worker API
  • 1.4 MA多头/空头排列是真的吗?
  • 基于SpringBoot+Vue的CSGO赛事管理系统设计与实现(源码+LW+部署文档等)
  • Android系统APP之SettingsProvider
  • go入门实践二-tcp服务端
  • SprinMVC获取请求参数
  • orangepi 4lts ubuntu安装RabbitMQ