【发布时间】:2018-03-08 16:44:38
【问题描述】:
我想在 Instagram 中搜索一个特殊关键字。例如,我想搜索这个词:“快餐”。我可以在搜索框中发送此密钥。但是,当我通过 Python3 在 Selenium 中使用提交方法时,它不起作用并给我错误。这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Firefox()
url="https://www.instagram.com/p/pTPI-kyX7g/?tagged=resurant"
driver.get(url)
#login_button=driver.find_element_by_xpath("""/html/body/span/section/main/article/div[2]/div[2]/p/a""")
#login_button.click()
import time
driver.implicitly_wait(5)
search_button=driver.find_element_by_xpath("""/html/body/span/section/nav/div[2]/div/div/div[2]/input""")
search_button.send_keys("fast food")
search_button.submit()
这是错误的:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ./ancestor-or-self::form
你能帮帮我吗?
【问题讨论】:
-
你能提供相关的HTML吗?
-
-
在哪个代码行给出了异常。我没有看到异常中提到的带有定位器的代码行。
-
-
比之前的代码更完善。你需要xpath吗?
标签: python-3.x selenium submit instagram enter