You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用get_attribute提取<a>标签中Instagram验证码失败,求助

你之前用get_attribute("name")和get_attribute("value")失败,是因为这个<a>标签根本没有name和value属性——验证码是在标签的文本内容里,不是属性值。

正确步骤如下:

  • 先定位到这个<a>元素
  • 获取元素的文本内容
  • 从文本里提取数字验证码

代码示例(Python + Selenium)

from selenium import webdriver
from selenium.webdriver.common.by import By
import re

# 定位元素(这里用class属性定位,也可以用data-mail-id等其他属性)
element = driver.find_element(By.CLASS_NAME, "viewLink")

# 获取元素的文本内容
code_text = element.text  # 或者用 element.get_attribute("innerText")

# 提取文本中的数字验证码
verification_code = re.search(r'\d+', code_text).group()
print(verification_code)  # 输出:637452

补充说明

  • 如果你用的是其他语言(比如Java),逻辑一致:先获取元素文本,再用正则提取数字
  • 也可以直接用XPath或CSS选择器配合文本匹配定位,但提取数字仍需正则处理

内容的提问来源于stack exchange,提问作者Glassy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 13:15:34