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

相关推荐
威联通网络存储23 分钟前
某新能源汽车研发中心:基于威联通的全闪存数据治理实践
python·汽车
清空mega26 分钟前
第4章:JSP 程序设计实战——for、if、动态表格与 99 乘法表
开发语言·python
阿钱真强道38 分钟前
06 Python 数据分析入门:集中趋势与离散程度
python·数据挖掘·数据分析·pandas·可视化·python入门·统计学
敲个大西瓜1 小时前
AI 基础设施 RAG工程
人工智能·python
爱凤的小光1 小时前
Wireshark长时间循环抓包操作说明
网络·测试工具·wireshark
曾阿伦1 小时前
Python项目管理从Poetry迁移到uv:极速体验与实操指南
开发语言·python·uv
2301_818730561 小时前
turtle学习
python
AnalogElectronic1 小时前
windows文件加解密工具,python实现,速度极快,篡改文件头尾信息以及还原
开发语言·windows·python
m0_528174451 小时前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python