selenium爬取span内的文字
时间: 2023-12-02 21:31:51 浏览: 174
可以通过以下代码使用 Selenium 爬取 span 标签内的文字:
```python
from selenium import webdriver
# 创建浏览器对象
driver = webdriver.Chrome()
# 访问页面
driver.get("http://example.com")
# 找到 span 标签
span = driver.find_element_by_xpath("//span")
# 获取 span 标签内的文字
text = span.text
# 打印结果
print(text)
# 关闭浏览器
driver.quit()
```
其中,`xpath` 参数可以根据具体的页面结构进行修改,以定位到需要的 span 标签。`text` 属性可以获取标签内的文字。
阅读全文
相关推荐









