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

相关推荐
he___H21 小时前
基于LCEL的联想
开发语言·python·langchain
想会飞的蒲公英1 天前
TF-IDF + 随机森林中文文本分类全链路实战:从训练脚本到 Flask API + Streamlit 前端
人工智能·pytorch·python·随机森林·分类·flask·tf-idf
FriendshipT1 天前
Ultralytics:解读C3模块
人工智能·pytorch·python·深度学习·目标检测
极光代码工作室1 天前
基于深度学习的异常行为检测系统
人工智能·python·深度学习·神经网络·机器学习
承渊政道1 天前
【Python学习】(了解Python背景知识、搭建 Python 环境以及安装PyCharm)
python·学习·pycharm·搭建python环境
川石课堂软件测试1 天前
性能测试|Nginx中间件监控与调优
linux·python·nginx·中间件·单元测试·压力测试·harmonyos
Lyn_Li1 天前
扫描 PDF 歪了怎么办?用 6 种检测方法做本地批量扶正(附开源工具)
python·pdf·ocr·tesseract·开源工具·文档处理·本地处理·扫描件纠偏
金銀銅鐵1 天前
费马小定理
python·数学·算法
疋瓞1 天前
python和C++对比(1)_数据类型和数据结构
数据结构·c++·python
如此这般英俊2 天前
手搓Claude Code-第六章 subagent
数据结构·人工智能·python·语言模型·自然语言处理