Python爬虫——selenium_访问元素信息

python 复制代码
from selenium import webdriver

# 创建浏览器对象
path = 'files/chromedriver.exe'
browser = webdriver.Chrome(path)

# 访问地址
url = 'https://www.baidu.com'
browser.get(url)

input = browser.find_element_by_id('su')
  1. 获取元素属性
python 复制代码
.get_attribute('class')
python 复制代码
print(input.get_attribute('class'))
  1. 获取标签名
python 复制代码
.tag_name
python 复制代码
print(input.tag_name)
  1. 获取元素文本
python 复制代码
.text
python 复制代码
a = browser.find_element_by_link_text('hao123')
print(a.text)
相关推荐
清水白石0083 小时前
突破并行瓶颈:Python 多进程开销全解析与 IPC 优化实战
开发语言·网络·python
Lupino4 小时前
IoT 平台可编程化:基于 Pydantic Monty 构建工业级智能自动化链路
python
清水白石0085 小时前
突破性能瓶颈:深度解析 Numba 如何让 Python 飙到 C 语言的速度
开发语言·python
yunhuibin6 小时前
AlexNet网络学习
人工智能·python·深度学习·神经网络
喵手7 小时前
Python爬虫实战:增量爬虫实战 - 利用 HTTP 缓存机制实现“极致减负”(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·增量爬虫·http缓存机制·极致减负
一个处女座的程序猿O(∩_∩)O8 小时前
Python异常处理完全指南:KeyError、TypeError、ValueError深度解析
开发语言·python
was1728 小时前
使用 Python 脚本一键上传图片到兰空图床并自动复制链接
python·api上传·自建图床·一键脚本
好学且牛逼的马8 小时前
从“Oak”到“虚拟线程”:JDK 1.0到25演进全记录与核心知识点详解a
java·开发语言·python
shangjian0078 小时前
Python基础-环境安装-Anaconda配置虚拟环境
开发语言·python
codeJinger8 小时前
【Python】函数
开发语言·python