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

相关推荐
@forever@1 天前
【JAVA】LinkedList与链表
java·python·链表
程序员爱钓鱼1 天前
Python编程实战:面向对象与进阶语法——类型注解与代码规范(PEP 8)
后端·python·ipython
程序员爱钓鱼1 天前
Python实战:用高德地图API批量获取地址所属街道并写回Excel
后端·python·ipython
reasonsummer1 天前
【教学类-97-06】20251105“葡萄”橡皮泥黏贴(小班主题《苹果与橘子》)
python
测试老哥1 天前
Jmeter+Maven+jenkins+eclipse 搭建自动化测试平台
自动化测试·软件测试·测试工具·jmeter·jenkins·maven·性能测试
卖个几把萌1 天前
【16】Selenium+Python 接管已打开谷歌浏览器
python·selenium·测试工具
像风一样的男人@1 天前
python --两个文件夹文件名比对(yolo 图和label标注比对检查)
windows·python·yolo
lllsure1 天前
【Python】Dict(字典)
开发语言·python
tianyuanwo1 天前
Rust开发完全指南:从入门到与Python高效融合
开发语言·python·rust
如何原谅奋力过但无声1 天前
TensorFlow 2.x常用函数总结(持续更新)
人工智能·python·tensorflow