使用Selenium浏览器自动抓取cabrbetc网站的样品信息

from selenium import webdriver

from bs4 import BeautifulSoup

import time

'''

#根据委托编号创建查询网址

text = "BETC-HJ-2024-P-00362"

url = "http://weixin.cabr-betc.com/gjwx/wxfind/findreport?prtnum="+text

print(url)

'''

将委托单位名称转化成utf-8格式,并用%连接转化后16进制,导入cabr-betc报告的查询网址url中

text = "中寓装配(江苏)新材料有限公司"

utf8_encoded_text = text.encode('utf-8')

hex_representation = '%'.join(hex(b)[2:] for b in utf8_encoded_text)

#print(hex_representation)

url = "http://weixin.cabr-betc.com/gjwx/wxfind/findreport?prtnum=\&xmname=\&wtunit=%"+hex_representation+"\&page=1\&rows=1000"

print(url)

创建 Chrome 浏览器驱动实例

driver = webdriver.Chrome()

打开指定网址

driver.get(url)

等待页面加载完成,可根据实际情况调整等待时间

time.sleep(5)

获取页面源代码

page_source = driver.page_source

使用 BeautifulSoup 解析页面源代码

soup = BeautifulSoup(page_source, 'html.parser')

查找所有报告编号元素并打印

report_numbers = soup.find_all('div', class_='weui-cell__bd')

for number in report_numbers:

print(number.text)

关闭浏览器驱动

driver.close()

相关推荐
CHANG_THE_WORLD4 分钟前
Python 可变参数详解与代码示例
java·前端·python
渡我白衣6 分钟前
计算机组成原理(3):计算机软件
java·c语言·开发语言·jvm·c++·人工智能·python
白露与泡影10 分钟前
从 JDK 8 到 JDK 18,Java 垃圾回收的十次进化
java·开发语言·测试工具
小霖家的混江龙19 分钟前
Token 到底怎么来的? 一文读懂大模型分词的核心逻辑, 看完秒懂!
人工智能·python·llm
曲幽20 分钟前
Flask进阶必备:掌握中间件、钩子和扩展
python·flask·web·request·cors·wsgi
hiber98730 分钟前
SLM-Lab安装过程(踩坑过程)
python·slm-lab
我的xiaodoujiao30 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 30--开源电商商城系统项目实战--配置测试环境地址
python·学习·测试工具·pytest
海上飞猪34 分钟前
【Python】JSON的基本使用-JSON 模式(Schema)与数据解析
开发语言·python·json
4***997435 分钟前
工业网关助力Altivar320与S7-1200协同运行
ide·python·算法·spring·eclipse·sqlite·tornado
IT·小灰灰35 分钟前
DeepSeek-V3.2:开源大模型的里程碑式突破与硅基流动平台实战指南
大数据·人工智能·python·深度学习·算法·数据挖掘·开源