使用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()

相关推荐
曲径海盗16 分钟前
【Python 学习第 38 天】for 循环
python·学习笔记·编程入门
在世修行40 分钟前
智学文枢:变式题生成引擎
python·ai·pyside·题目生成
On The Road :2 小时前
Java 多线程详解:从入门到线程安全
java·python·安全
岁月宁静3 小时前
如何设计支持 Skills 的 Agent?一套可扩展的四层架构
python·agent
岁月宁静3 小时前
CrewAI 快速上手:10 分钟搭建你的第一个 Agent 团队
python·agent
曲径海盗3 小时前
【Python 学习第 40 天】for 循环
python·学习笔记·编程入门
专注仿真3 小时前
知识问答大模型-rag算法详解
人工智能·python·控制算法
染指11104 小时前
158.Agent-LangGraph-子图(共享状态和不共享状态模式)
开发语言·人工智能·python·ui·agent·agents
云和数据.ChenGuang5 小时前
Python 常见特殊方法详解:__new__、__init__、__del__、__str__、__repr__ 与 __getattribute__
开发语言·人工智能·python·1024程序员节
xyouyuweizhu6 小时前
字节流与字符流:Java IO 的两条主线该怎么选
java·开发语言·python