首页 > 解决方案 > 如何找到用于scrapy(爬行)的元素iTunes Connect网站?

问题描述

我需要我的应用程序的 CFBundleversion,所以我尝试了scrapy iTunes Connect 网站,但我无法获得元素。

我试过了:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("https://appstoreconnect.apple.com/login")

elem = driver.find_element_by_xpath("//input[@id='account_name_text_field']")

我收到以下错误:

elenium.common.exceptions.NoSuchElementException:消息:无法找到元素://input[@id='account_name_text_field']

我认为该网站的结构不同...我该怎么办?

标签: pythonseleniumscrapyweb-crawler

解决方案


你的定位器没有问题:

driver.find_element_by_xpath("//input[@id='account_name_text_field']")

它里面iframe,你需要先切换,使用frame_to_be_available_and_switch_to_itand visibility_of_element_located,像这样:

driver.get('https://appstoreconnect.apple.com/login')

WebDriverWait(driver, 30).until(expected_conditions.frame_to_be_available_and_switch_to_it((By.ID, "aid-auth-widget-iFrame")))
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located((By.XPATH, "//input[@id='account_name_text_field']")))
elem = driver.find_element_by_xpath("//input[@id='account_name_text_field']")
elem.send_keys("userName")

导入后:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

推荐阅读