Script which works on PC1 doesn't work on PC2 - python

a friend of mine wrote me a piece of code which does a web automation for me which im running on a VPS.
On VPS 1 the script has been running for days without a problem.
Now I wanted to do the same on a different VPS.
Its an older windows version of win 10 I don't know if that plays a role*
Chrome version on VPS 1 is 102
If I try to install chrome on VPS 2 it updates automatically to 103 so I tried downloaded version 102 over this link : https://www.slimjet.com/chrome/google-chrome-old-version.php but it still auto updates to 103 so i ended up running the 103 chrome driver instead of the 102 on VPS1
For the rest I installed everything completely the same on VPS 1 on VPS2
Selenium version 4.1.5
But now all it does it that it opens the browser with the link but it doesn't do any actions and I don't know what the error means.
I will put the code in here (some things censored because of personal information) + the error I get
import schedule
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains
exec_times = ["13:17"]
wert = "5"
id = "ID: CENSORED"
def do_purchase():
PATH = "C:\\Users\\Administrator\\Desktop\\bumping\\chromedriver.exe"
URL = "URL CENSORED"
options = Options()
options.add_argument(
"user-data-dir=C:\\Users\\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data")
driver = webdriver.Chrome(PATH, chrome_options=options)
driver.get(URL)
time.sleep(10)
div = div = driver.find_element_by_xpath(
"//*[contains(text(), '{}')]".format(id))
parent = div.find_element_by_xpath('..')
buttons = parent.find_elements_by_tag_name('button')
button = buttons[0]
hover = ActionChains(driver).move_to_element(parent)
hover.perform()
time.sleep(2)
webdriver.ActionChains(driver).move_to_element(
button).click(button).perform()
time.sleep(3)
inputs = driver.find_elements_by_xpath(
"//*[contains(text(), 'Transfer amount')]")
parent = inputs[0].find_element_by_xpath('..')
input = parent.find_element_by_tag_name('input')
input.clear()
input.send_keys(wert)
confirm_span = driver.find_element_by_xpath(
"//*[contains(text(), 'Confirm')]")
confirm_button = confirm_span.find_element_by_xpath('..')
webdriver.ActionChains(driver).move_to_element(
confirm_button).click(confirm_button).perform()
time.sleep(5)
driver.quit()
def task(time):
do_purchase()
for exec_time in exec_times:
schedule.every().day.at(exec_time).do(task, exec_time)
while True:
schedule.run_pending()
time.sleep(1)
The terminal says the following
PS C:\Users\Administrator> & C:/Users/Administrator/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/Administrator/Desktop/bumping/Client 1.py"
c:\Users\Administrator\Desktop\bumping\Client 1.py:19: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(PATH, chrome_options=options)
c:\Users\Administrator\Desktop\bumping\Client 1.py:19: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome(PATH, chrome_options=options)
DevTools listening on ws://127.0.0.1:64181/devtools/browser/854481e2-f194-46a1-8421-8dab5852169d
Traceback (most recent call last):
File "c:\Users\Administrator\Desktop\bumping\Client 1.py", line 65, in <module>
schedule.run_pending()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 780, in run_pending
default_scheduler.run_pending()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 100, in run_pending
self._run_job(job)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 172, in _run_job
ret = job.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 661, in run
ret = self.job_func()
File "c:\Users\Administrator\Desktop\bumping\Client 1.py", line 57, in task
do_purchase()
File "c:\Users\Administrator\Desktop\bumping\Client 1.py", line 20, in do_purchase
driver.get(URL)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 442, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: unexpected command response
(Session info: chrome=103.0.5060.53)
Stacktrace:
Backtrace:
Ordinal0 [0x0060D953+2414931]
Ordinal0 [0x0059F5E1+1963489]
Ordinal0 [0x0048C6B8+837304]
Ordinal0 [0x0047EB34+781108]
Ordinal0 [0x0047E06A+778346]
Ordinal0 [0x0047D646+775750]
Ordinal0 [0x0047C565+771429]
Ordinal0 [0x0047CB68+772968]
Ordinal0 [0x0048785F+817247]
Ordinal0 [0x0049255B+861531]
Ordinal0 [0x00494F70+872304]
Ordinal0 [0x0047CE36+773686]
Ordinal0 [0x00492197+860567]
Ordinal0 [0x004E4B55+1198933]
Ordinal0 [0x004D42B6+1131190]
Ordinal0 [0x004AE860+976992]
Ordinal0 [0x004AF756+980822]
GetHandleVerifier [0x0087CC62+2510274]
GetHandleVerifier [0x0086F760+2455744]
GetHandleVerifier [0x0069EABA+551962]
GetHandleVerifier [0x0069D916+547446]
Ordinal0 [0x005A5F3B+1990459]
Ordinal0 [0x005AA898+2009240]
Ordinal0 [0x005AA985+2009477]
Ordinal0 [0x005B3AD1+2046673]
BaseThreadInitThunk [0x750D62C4+36]
RtlSubscribeWnfStateChangeNotification [0x77E20969+1081]
RtlSubscribeWnfStateChangeNotification [0x77E20934+1028]
Help would be hugely appreciated

Related

Selenium: Chrome Driver not starting in python

Explaination:
I am Getting some error codes while I am trying to run Chrome driver in my python selenium code.
I already checked the Chrome version compatibility, and its compatible.
Environment variables are also set.
Code I am trying to run:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options= chrome_options)
Error that I am Getting:
Traceback (most recent call last):
File "C:/Users/ayush/OneDrive - Mine/Workspace/Python/main.py", line 8, in <module>
driver = webdriver.Chrome(options= chrome_options)
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
super().__init__(
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 272, in __init__
self.start_session(capabilities, browser_profile)
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 364, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "C:\ProgramData\App-V\6535534A-D380-471D-B8F1-7BD034353DFE\A468717B-AA22-4950-8A85-D1FE39461A2D\Root\VFS\ProgramFilesX86\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
Ordinal0 [0x002A1ED3+2236115]
Ordinal0 [0x002392F1+1807089]
Ordinal0 [0x001466FD+812797]
Ordinal0 [0x001658F9+940281]
Ordinal0 [0x001619C9+924105]
Ordinal0 [0x0019806C+1146988]
Ordinal0 [0x00197A6A+1145450]
Ordinal0 [0x001918A6+1120422]
Ordinal0 [0x0016A73D+960317]
Ordinal0 [0x0016B71F+964383]
GetHandleVerifier [0x0054E7E2+2743074]
GetHandleVerifier [0x005408D4+2685972]
GetHandleVerifier [0x00332BAA+532202]
GetHandleVerifier [0x00331990+527568]
Ordinal0 [0x0024080C+1837068]
Ordinal0 [0x00244CD8+1854680]
Ordinal0 [0x00244DC5+1854917]
Ordinal0 [0x0024ED64+1895780]
BaseThreadInitThunk [0x7622FA29+25]
RtlGetAppContainerNamedObjectPath [0x773E7B5E+286]
RtlGetAppContainerNamedObjectPath [0x773E7B2E+238]
(No symbol) [0x00000000]
Can Someone explain what this error is all about?

Web scraping script works fine most of the time, but occassionally it throws me an error. What does it mean?

My script basically lets user input a link, goes to that website, find a specific element from the website, and check if it matches the previous web scraping result of the same element.
If the result is same as last time, nothing happens.
If the result is different than last time, notify user.
The script does web scraping with that link once every 3 minutes automatically, without asking for user inputs again. So user only needs to input the link once and it will continue running using the same link.
It works fine mostly, it can run for hours without problem. But occasionally, very rarely, it would throw me an error:
Traceback (most recent call last):
File "C:\Users\User\Documents\TTC_Sniper\ttc_sniper6.py", line 283, in <module>
schedule.run_pending()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 780, in run_pending
default_scheduler.run_pending()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 100, in run_pending
self._run_job(job)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 172, in _run_job
ret = job.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\schedule\__init__.py", line 661, in run
ret = self.job_func()
File "C:\Users\User\Documents\TTC_Sniper\ttc_sniper6.py", line 238, in TTC_Sniper
Snipe2(prev_input2)
File "C:\Users\User\Documents\TTC_Sniper\ttc_sniper6.py", line 130, in Snipe2
Snipe1(page_url1, count+1)
File "C:\Users\User\Documents\TTC_Sniper\ttc_sniper6.py", line 62, in Snipe1
all_comments = OpenBrowser(page_url1)
File "C:\Users\User\Documents\TTC_Sniper\ttc_sniper6.py", line 30, in OpenBrowser
driver.get(page_url)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
self.error_handler.check_response(response)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: headless chrome=105.0.5195.127)
Stacktrace:
Backtrace:
Ordinal0 [0x0085DF13+2219795]
Ordinal0 [0x007F2841+1779777]
Ordinal0 [0x00704100+803072]
Ordinal0 [0x006F760A+751114]
Ordinal0 [0x006F61A8+745896]
Ordinal0 [0x006F63FD+746493]
Ordinal0 [0x00705A8E+809614]
Ordinal0 [0x0075F87D+1177725]
Ordinal0 [0x0074E7FC+1107964]
Ordinal0 [0x0075F192+1175954]
Ordinal0 [0x0074E616+1107478]
Ordinal0 [0x00727F89+950153]
Ordinal0 [0x00728F56+954198]
GetHandleVerifier [0x00B52CB2+3040210]
GetHandleVerifier [0x00B42BB4+2974420]
GetHandleVerifier [0x008F6A0A+565546]
GetHandleVerifier [0x008F5680+560544]
Ordinal0 [0x007F9A5C+1808988]
Ordinal0 [0x007FE3A8+1827752]
Ordinal0 [0x007FE495+1827989]
Ordinal0 [0x008080A4+1867940]
BaseThreadInitThunk [0x772CFA29+25]
RtlGetAppContainerNamedObjectPath [0x777B7B5E+286]
RtlGetAppContainerNamedObjectPath [0x777B7B2E+238]
I don't know what it means.
I Googled a bit, and some people said selenium.common.exceptions.InvalidArgumentException: Message: invalid argument is caused by issues within the url itself, such as forgetting to add "https:" or containing a space.
I'm pretty sure this isn't the problem because the code has been running for about an hour before this error shows up. Also once I run the code again using the exact same link again, it works again.
Like I said, it happens only occasionally, seemingly randomly.
I don't know what could be causing this problem and I would like to know how to prevent it/make it notify me in case this happens.
If it helps, this is the part of my code that does web scraping.
def OpenBrowser(page_url):
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(page_url)
time.sleep(3)
html = driver.find_element(By.TAG_NAME, 'html')
elems1 = driver.find_elements("xpath", '/html/body/div[2]/table/tbody/tr[2]/td[2]/section/div')
all_comments = [elem1.text for elem1 in elems1]
return all_comments

Can't use Selenium with for loop

I am trying to write a program with for loop and for that I need to declare Selenium webdriver before the loop.
Each time I am trying to do it I get an error. Like the loop doesn't recognize driver.get part.
Here is the code:
from selenium import webdriver
import time
import csv
with open('smlxl.csv', 'r') as myFile:
myReader = csv.reader(myFile)
myList = list(myReader)
driver = webdriver.Chrome(executable_path='C:\Program Files (x86)\chromedriver.exe')
for n in range(1,1000,4):
barcode = (myList[n][24])
url = ("https://www.google.com/search?q=" + barcode)
driver.get(url)
print(n)
n = (n+4)
time.sleep(3)
driver.close()
The error I get:
C:\Users\DELL\PycharmProjects\pythonProject3\erro.py:10: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path='C:\Program Files (x86)\chromedriver.exe')
1
Traceback (most recent call last):
File "C:\Users\DELL\PycharmProjects\pythonProject3\erro.py", line 16, in <module>
driver.get(url)
File "C:\Users\DELL\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 447, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\DELL\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "C:\Users\DELL\PycharmProjects\pythonProject3\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id
Stacktrace:
Backtrace:
Ordinal0 [0x00326463+2188387]
Ordinal0 [0x002BE461+1762401]
Ordinal0 [0x001D3C40+801856]
Ordinal0 [0x001F68BD+944317]
Ordinal0 [0x001F7AD6+948950]
GetHandleVerifier [0x005C71F2+2712546]
GetHandleVerifier [0x005B886D+2652765]
GetHandleVerifier [0x003B002A+520730]
GetHandleVerifier [0x003AEE06+516086]
Ordinal0 [0x002C468B+1787531]
Ordinal0 [0x002C8E88+1805960]
Ordinal0 [0x002C8F75+1806197]
Ordinal0 [0x002D1DF1+1842673]
BaseThreadInitThunk [0x7587FA29+25]
RtlGetAppContainerNamedObjectPath [0x770D7A9E+286]
RtlGetAppContainerNamedObjectPath [0x770D7A6E+238]
Process finished with exit code 1
Thank you for helping
Had to place driver.close() outside the for loop.
These error message...
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id
...implies that the previous session wasn't successfully killed/removed/eliminated.
Solution
You need to replace:
driver.close()
with:
driver.quit()
References
You can find a couple of relevant detailed discussions in:
selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python

Selenium Python not scraping from this website

I was trying to interact with this website using Selenium in python. I wrote this code to select the radio button using XPATH. But some weird error is showing in my terminal. Can anyone please solve this problem? I tried but can't figure out the problem.
My code.
from select import select
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import csv
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get('https://www2.illinois.gov/idoc/Offender/Pages/InmateSearch.aspx')
button = driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table[2]/tbody/tr/td[1]/table/tbody/tr/td/form/table/tbody/tr/td/input[2]')
button.click()
driver.implicitly_wait(10)
driver.quit()
Error :
DevTools listening on ws://127.0.0.1:62348/devtools/browser/ce37da62-856d-4159-ad45-9eca8e63115a
E:\Fiverr job\Orders\1\test.py:18: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
button = driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table[2]/tbody/tr/td[1]/table/tbody/tr/td/form/table/tbody/tr/td/input[2]')
Traceback (most recent call last):
File "E:\Fiverr job\Orders\1\test.py", line 18, in <module>
button = driver.find_element_by_xpath('/html/body/table/tbody/tr/td/table[2]/tbody/tr/td[1]/table/tbody/tr/td/form/table/tbody/tr/td/input[2]')
File "E:\Fiverr job\Orders\1\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 526, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "E:\Fiverr job\Orders\1\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1251, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "E:\Fiverr job\Orders\1\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "E:\Fiverr job\Orders\1\env\lib\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":"xpath","selector":"/html/body/table/tbody/tr/td/table[2]/tbody/tr/td[1]/table/tbody/tr/td/form/table/tbody/tr/td/input[2]"}
(Session info: chrome=102.0.5005.63)
Stacktrace:
Backtrace:
Ordinal0 [0x0054D953+2414931]
Ordinal0 [0x004DF5E1+1963489]
Ordinal0 [0x003CC6B8+837304]
Ordinal0 [0x003F9500+1021184]
Ordinal0 [0x003F979B+1021851]
Ordinal0 [0x00426502+1205506]
Ordinal0 [0x004144E4+1131748]
Ordinal0 [0x00424812+1198098]
Ordinal0 [0x004142B6+1131190]
Ordinal0 [0x003EE860+976992]
Ordinal0 [0x003EF756+980822]
GetHandleVerifier [0x007BCC62+2510274]
GetHandleVerifier [0x007AF760+2455744]
GetHandleVerifier [0x005DEABA+551962]
GetHandleVerifier [0x005DD916+547446]
Ordinal0 [0x004E5F3B+1990459]
Ordinal0 [0x004EA898+2009240]
Ordinal0 [0x004EA985+2009477]
Ordinal0 [0x004F3AD1+2046673]
BaseThreadInitThunk [0x7648FA29+25]
RtlGetAppContainerNamedObjectPath [0x77BE7A7E+286]
RtlGetAppContainerNamedObjectPath [0x77BE7A4E+238]
This is because the element you try to click is located into an iframe:
So you must first switch to it before finding and clicking the desired button:
import time
driver = webdriver.Chrome(options=options, desired_capabilities=capabilities)
driver.get('https://www2.illinois.gov/idoc/Offender/Pages/InmateSearch.aspx')
#wait a little to be sure the iframe is loaded
time.sleep(2)
#find and switch to the iframe
iframe = driver.find_element(By.XPATH, '//*[#id="soi-iframe"]')
driver.switch_to.frame(iframe)
button = driver.find_element(By.XPATH, '/html/body/table/tbody/tr/td/table[2]/tbody/tr/td[1]/table/tbody/tr/td/form/table/tbody/tr/td/input[2]')
button.click()
driver.quit()
Proof of work: (click on pic to zoom in)

When i try to scrape this website with selenium and python

When i try and scrape the website it just throws some errors
I think it may have something to do with my webdriver but idk
I am trying to get this data so i can put it in a spreadsheet to get some cool staticstics
from selenium import webdriver
url = 'https://prosettings.net/cs-go-pro-settings-gear-list/'
driver = webdriver.Chrome(executable_path="C:\WebDrivers\chromedriver.exe")
driver.get(url)
names = driver.find_elements_by_class_name(" column-player")
for name in names:
title = name.find_element_by_xpath('.//a').text
print(name)
Here are the error i get in terminal
d:\downloads\PythonScraping\Test.py:5: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path="C:\WebDrivers\chromedriver.exe")
DevTools listening on ws://127.0.0.1:53131/devtools/browser/73ca0453-352e-47a0-a98a-fb539150d6f9
d:\downloads\PythonScraping\Test.py:8: DeprecationWarning: find_elements_by_* commands are deprecated. Please use find_elements() instead
names = driver.find_elements_by_class_name(" column-player")
Traceback (most recent call last):
File "d:\downloads\PythonScraping\Test.py", line 8, in <module>
names = driver.find_elements_by_class_name(" column-player")
File "C:\Users\terk0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 783, in
find_elements_by_class_name
return self.find_elements(by=By.CLASS_NAME, value=name)
File "C:\Users\terk0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 1279, in find_elements
return self.execute(Command.FIND_ELEMENTS, {
File "C:\Users\terk0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in
execute
self.error_handler.check_response(response)
File "C:\Users\terk0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 247,
in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
(Session info: chrome=98.0.4758.102)
Stacktrace:
Backtrace:
Ordinal0 [0x00EF69A3+2582947]
Ordinal0 [0x00E8A6D1+2139857]
Ordinal0 [0x00D83A98+1063576]
Ordinal0 [0x00D862B7+1073847]
Ordinal0 [0x00D8617E+1073534]
Ordinal0 [0x00D863F0+1074160]
Ordinal0 [0x00DAFCB2+1244338]
Ordinal0 [0x00DB013B+1245499]
Ordinal0 [0x00DD9F8C+1417100]
Ordinal0 [0x00DC8594+1344916]
Ordinal0 [0x00DD834A+1409866]
Ordinal0 [0x00DC8366+1344358]
Ordinal0 [0x00DA5176+1200502]
Ordinal0 [0x00DA6066+1204326]
GetHandleVerifier [0x0109BE02+1675858]
GetHandleVerifier [0x0115036C+2414524]
GetHandleVerifier [0x00F8BB01+560977]
GetHandleVerifier [0x00F8A8D3+556323]
Ordinal0 [0x00E9020E+2163214]
Ordinal0 [0x00E95078+2183288]
Ordinal0 [0x00E951C0+2183616]
Ordinal0 [0x00E9EE1C+2223644]
BaseThreadInitThunk [0x7586FA29+25]
RtlGetAppContainerNamedObjectPath [0x77957A9E+286]
RtlGetAppContainerNamedObjectPath [0x77957A6E+238]
There are 2 problems here:
Instead of
names = driver.find_elements_by_class_name(" column-player")
it should be
names = driver.find_elements_by_class_name("column-player")
(I know, there are spaces before column-player class name there, but you still should not put them inside the locator)
2) You should add a delay to access these elements only after the page have been completely loaded.
This should work better:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = 'https://prosettings.net/cs-go-pro-settings-gear-list/'
driver = webdriver.Chrome(executable_path="C:\WebDrivers\chromedriver.exe")
wait = WebDriverWait(driver, 20)
driver.get(url)
#wait for at least 1 element visibility
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".column-player")))
#short additional wait for all the other elements to complete loading
time.sleep(0.5)
names = driver.find_elements_by_class_name("column-player")
for name in names:
title = name.find_element_by_xpath('.//a').text
print(name)

Categories

Resources