简体   繁体   English

未知的 Python Selenium 错误:Traceback(最近一次调用最后一次):文件“D:\pythonProject\webscraping.py”,第 17 行,在<module>

[英]Unknown Python Selenium error:Traceback (most recent call last): File "D:\pythonProject\webscraping.py", line 17, in <module>

I am making this little program for Minecraft as a little program for fun and practicing python.我正在为 Minecraft 制作这个小程序,作为一个有趣和练习 python 的小程序。 I am using selenium and when I was trying to get the name of something in the HTML webpage with find_element it gave me this massive error code:我正在使用 selenium,当我尝试使用 find_element 在 HTML 网页中获取某些内容的名称时,它给了我这个巨大的错误代码:

Traceback (most recent call last):
  File "D:\pythonProject\webscraping.py", line 17, in <module>
    username = driver.find_element(By.NAME, 'text-shadow: 1px 1px #eee; color:#3CE6E6')
  File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 1253, in find_element
    'value': value})['value']
  File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Han\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="text-shadow: 1px 1px #eee; color:#3CE6E6"]"}
  (Session info: chrome=103.0.5060.53)
Stacktrace:
Backtrace:
    Ordinal0 [0x00DB56B3+2184883]
    Ordinal0 [0x00D4E5F1+1762801]
    Ordinal0 [0x00C63DA8+802216]
    Ordinal0 [0x00C91B40+990016]
    Ordinal0 [0x00C91DDB+990683]
    Ordinal0 [0x00CBEC32+1174578]
    Ordinal0 [0x00CACB54+1100628]
    Ordinal0 [0x00CBCF52+1167186]
    Ordinal0 [0x00CAC926+1100070]
    Ordinal0 [0x00C86EA0+945824]
    Ordinal0 [0x00C87D96+949654]
    GetHandleVerifier [0x01054192+2704034]
    GetHandleVerifier [0x0104687D+2648461]
    GetHandleVerifier [0x00E4119A+529066]
    GetHandleVerifier [0x00E40006+524566]
    Ordinal0 [0x00D54F2B+1789739]
    Ordinal0 [0x00D59978+1808760]
    Ordinal0 [0x00D59A65+1808997]
    Ordinal0 [0x00D62A01+1845761]
    BaseThreadInitThunk [0x74F1FA29+25]
    RtlGetAppContainerNamedObjectPath [0x77097A9E+286]
    RtlGetAppContainerNamedObjectPath [0x77097A6E+238]

Here is my code for the program:这是我的程序代码:

from tqdm import tqdm
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

x=Service('C:\Program Files (x86)\chromedriver.exe')
driver = webdriver.Chrome(service=x)

pbar = tqdm(range(10))

for i in pbar:
    time.sleep(0.3)
    pbar.set_description("loading program")
PlankeName = input("Whos Planke Page would you like to view? ")
UserPlankeLink = "https://plancke.io/hypixel/player/stats/" + PlankeName
driver.get(UserPlankeLink)

username = driver.find_element(By.NAME, 'text-shadow: 1px 1px #eee; color:#3CE6E6')
print(username)
print("You are currently Viewing " + driver.title)

Please help!请帮忙!

Your error is NoSuchElementException because your element is not found.您的错误是NoSuchElementException因为找不到您的元素。 This exists because your identifier is wrong, or the page has not fully loaded yet.这是因为您的标识符错误,或者页面尚未完全加载。

I've had a look at your page - and your identifier is wrong.我看过你的页面 - 你的标识符是错误的。 But - It's also a poorly described website so it's a tricky one for beginners.但是 - 这也是一个描述不佳的网站,因此对于初学者来说是一个棘手的网站。

I updated it to use this xpath:我将其更新为使用此 xpath:

//div[h3[text()='Player Information']]//span[text()]

That is: From the div , which has the h3 inside it and where that h3 has text=player information - Get the span which has any text.即:从div中,其中包含h3并且h3具有 text=player 信息 - 获取包含任何文本的 span。

Using this this code:使用此代码:

driver = webdriver.Chrome() # note i modified this to my driver - reset to yours
driver.implicitly_wait(10)

PlankeName = input("Whos Planke Page would you like to view? ")
UserPlankeLink = "https://plancke.io/hypixel/player/stats/" + PlankeName
driver.get(UserPlankeLink)

username = driver.find_element(By.XPATH, "//div[h3[text()='Player Information']]//span[text()]")
print(username.text)
print("You are currently Viewing " + driver.title)

When entering the input test as the players name, I get output:当输入输入test作为玩家名称时,我得到输出:

You are currently Viewing Test's Stats | Plancke

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Traceback(最近一次调用最后一次):文件“D:\pythonProject\webscraping.py”,第 17 行,在<module> search.send_keys(Keys.RETURN) 错误 python - Traceback (most recent call last): File "D:\pythonProject\webscraping.py", line 17, in <module> search.send_keys(Keys.RETURN) Error python 回溯(最近一次调用最后一次):文件“D:\\Python\\PLAY.PY”,第 29 行,在<module> - Traceback (most recent call last): File "D:\Python\PLAY.PY", line 29, in <module> 获取错误消息 Traceback(最近一次调用最后一次):文件“input/code.py”,第 1 行,在<module> a= int(输入()) - Getting error message Traceback (most recent call last): File "input/code.py", line 1, in <module> a= int(input()) 回溯(最近调用最后):文件“main.py”,第 12 行,在<module>授权错误:TypeError: 'bool' object is not iterable</module> - Traceback (most recent call last): File "main.py", line 12, in <module> for error in authorisation: TypeError: 'bool' object is not iterable 回溯(最近一次调用最后一次):文件“main.py”,第 11 行,在<module> - Traceback (most recent call last): File "main.py", line 11, in <module> 我收到此错误:Traceback(最近调用最后一次):文件“./prog.py”,第 4 行,在<module>关键错误:“价格”</module> - I'm getting this error : Traceback (most recent call last): File "./prog.py", line 4, in <module> KeyError: 'price' 追溯(最近一次通话):“文件” <stdin> ”,第1行,在 <module> - Traceback (most recent call last): File “<stdin>”, line 1, in <module> Python Selenium Traceback(最近一次调用最后一次): - Python Selenium Traceback (most recent call last): 无法在python 3Traceback(最近一次调用为最新)中找出此错误:“文件” <stdin> ”,第1行,在 <module> NameError:未定义名称“ xlrd” - Cannot figure out this error in python 3Traceback (most recent call last): File “<stdin>”, line 1, in <module> NameError: name 'xlrd' is not defined Python追踪(最近一次通话)错误 - Python Traceback (most recent call last) error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM