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)
相关推荐
大数据魔法师12 小时前
Streamlit(二)- Streamlit 架构与运行机制
python·web
m0_4708576413 小时前
PHP怎么实现工厂模式_Factory模式编写指南【指南】
jvm·数据库·python
大数据魔法师13 小时前
Streamlit(三)- Streamlit 多页面应用开发
python·web
我的xiaodoujiao13 小时前
API 接口自动化测试详细图文教程学习系列20--结合Pytest框架使用
python·学习·测试工具·pytest
python在学ing13 小时前
前端-CSS学习笔记
前端·css·python·学习
深蓝电商API13 小时前
请求签名算法破解:从Chrome DevTools到Python还原的完整流程
爬虫·反爬
IT策士14 小时前
Django 从 0 到 1 打造完整电商平台:为什么用 Django 做电商?
后端·python·django
zkkkkkkkkkkkkk14 小时前
Linux进行管理工具Supervisor配置与使用
linux·python·supervisor
2301_7838486514 小时前
mysql数据库迁移到云平台流程_使用数据传输服务DTS工具
jvm·数据库·python
开发者联盟league15 小时前
linux普通用户使用pip安装模块
linux·python·pip