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

相关推荐
七夜zippoe7 分钟前
WebAssembly与Python:在浏览器中运行Python
开发语言·python·wasm·webassembly·pyscript
m0_6625779713 分钟前
自动化与脚本
jvm·数据库·python
telllong23 分钟前
消息总线设计:asyncio.Queue实战
python·架构设计·asyncio
伏 念1 小时前
大模型技术之LLM
人工智能·笔记·python·aigc
dapeng28701 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
站大爷IP1 小时前
使用 Python 实现 Word 文档文本格式化全解析
python
AI-小柒1 小时前
DataEyes 聚合平台 + Claude Code Max 编程实战
android·开发语言·人工智能·windows·python·macos·adb
SUBMAIL赛邮云通信1 小时前
如何用Python调用SUBMAIL SMS API发送国际短信
python
2401_874732531 小时前
构建一个桌面版的天气预报应用
jvm·数据库·python
qq_417695052 小时前
实战:用Python开发一个简单的区块链
jvm·数据库·python