Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 需要帮助创建用户名检查器,在动态网站中查找内容时遇到问题_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python 需要帮助创建用户名检查器,在动态网站中查找内容时遇到问题

Python 需要帮助创建用户名检查器,在动态网站中查找内容时遇到问题,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,这在这一行给了我一个错误“find=driver.find_element_by_class_name('jsx-4111167561 title')”,它说当我检查页面中的元素时可以找到这个类,但却找不到它 编辑: 我得到的错误代码是: import sys import os from selenium import webdriver import requests import re import time DRIVER_PATH = '/Users/x/Desktop/New Pr

这在这一行给了我一个错误“find=driver.find_element_by_class_name('jsx-4111167561 title')”,它说当我检查页面中的元素时可以找到这个类,但却找不到它

编辑:

我得到的错误代码是:

import sys
import os
from selenium import webdriver
import requests
import re
import time


DRIVER_PATH = '/Users/x/Desktop/New Project/chromedriver'
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
x = input("Enter a name: ")
driver = webdriver.Chrome(options=options, executable_path=DRIVER_PATH)


driver.get('https://www.tiktok.com/@'+str(x))

find = driver.find_element_by_class_name('jsx-4111167561 title')

if (find == "Couldn't find this account"):
    print("This name is available")
else:
    print("This name is unavailable")


driver.quit()

输入名称:testing123
回溯(最近一次呼叫最后一次):
文件“/Users/x/Desktop/New Project/check.py”,第25行,在
lookforit=driver。通过xpath('/*[contains(@class,“jsx-4111167561”)]'查找元素
文件“/Users/x/Library/Python/3.9/lib/Python/site packages/selenium/webdriver/remote/webdriver.py”,第394行,在find_元素中
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“/Users/x/Library/Python/3.9/lib/Python/site packages/selenium/webdriver/remote/webdriver.py”,第976行,在find_元素中
返回self.execute(Command.FIND_元素{
文件“/Users/x/Library/Python/3.9/lib/Python/site packages/selenium/webdriver/remote/webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“/Users/x/Library/Python/3.9/lib/Python/site packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“xpath”,“选择器”:“/*[contains(@class,“jsx-4111167561”)]”
(会话信息:无头镀铬=91.0.4472.101)

类名中的空格表示它实际上有两个css类……”jsx-4111167561“和”title“。我认为有各种解决方法,但我喜欢使用//*[contains(@class,“jsx-4111167561”)]的XPATH。也可以看到这个线程:我尝试了这个,但仍然得到相同的错误。我编辑了这篇文章,以显示我得到的错误。
Enter a name: testing123
Traceback (most recent call last):
  File "/Users/x/Desktop/New Project/check.py", line 25, in <module>
    lookforit = driver.find_element_by_xpath('//*[contains(@class, "jsx-4111167561")]').text
  File "/Users/x/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Users/x/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "/Users/x/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/x/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(@class, "jsx-4111167561")]"}
  (Session info: headless chrome=91.0.4472.101)