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

相关推荐
chenment13 小时前
ComfyUI 自定义节点开发:从零扩展你的图像生成工作流
python·stable diffusion
互联网中的一颗神经元14 小时前
小白python入门 - 25. SQL 与表设计入门
数据库·python·sql
RSTJ_162515 小时前
PYTHON+AI LLM DAY ONE HUNDRED AND EIGHTEEN
python
开源量化GO15 小时前
近期量化学习路径,交易理解和技术实现要接上
人工智能·python
c_lb728816 小时前
近期手工规则量化,学习表达到开发验证要连起来
人工智能·python
tkevinjd16 小时前
MiniCode 项目详解7:Memory 记忆系统
大数据·python·搜索引擎·llm·agent
郭老二17 小时前
【Python】Web框架 FastAPI 详解
python·fastapi
DFT计算杂谈17 小时前
交错磁研究进展材料物性与交叉应用
数据库·人工智能·python·opencv·算法
敖行客 Allthinker17 小时前
docker容器安装Python反推镜像步骤(适用于临时调试用)
python·docker·容器
rrrjqy17 小时前
夏普比率与 Beta——Quant-for-Beginners 量化入门Task7
python·金融