I m trying to open URLS From TXT file with selenium webdriver.But code is giving me error.Here is code that i m using with python 3.4.3.What can be the problem in this code?
from selenium import webdriver
with open("vps.txt","r") as fi:
urls = fi.read().splitlines()
for url in urls:
browser = webdriver.Firefox()
browser.get(url)
I get this error:
Traceback (most recent call last):
File "C:\pselenium\browse.py", line 8, in <module>
browser.get(url)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well-formed.
Stacktrace:
at FirefoxDriver.prototype.get (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/driver-component.js:10636)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well formed
It looks like you've got a problem with your file encoding. I'm not sure if that's the BOM or not, but you should check your file with a hex editor.
Related
Here is the code which I use to open the new tab using Selenium Python,
self.driver.execute_script("window.open(arguments[0])", self.listing_url)
self.driver.switch_to.window(self.driver.window_handles[1])
time.sleep(10)
and it works perfectly. But I am planning to use WebDriverWait instead of time.sleep
self.driver.execute_script("window.open(arguments[0])", self.listing_url)
self.driver.switch_to.window(self.driver.window_handles[1])
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//div[#class="honbun"]')))
and when I am using it, it's throwing an error. Here is the error log:
Traceback (most recent call last):
File "D:\tender_scraper\engine\Spider.py", line 308, in parse_index_page
index_handle = self.load_listing_page(listing, i, index_listing)
File "D:\tender_scraper\spiders\gunmapref_listing_spider.py", line 298, in load_listing_page
WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//div[#class="honbun"]')))
File "D:\scraper\lib\site-packages\selenium\webdriver\support\wait.py", line 78, in until
value = method(self._driver)
File "D:\scraper\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 64, in _predicate
return driver.find_element(*locator)
File "D:\scraper\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1251, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "D:\scraper\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "D:\scraper\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: missing or invalid columnNumber
(Session info: headless chrome=104.0.5112.48)
Any idea what's wrong with it & how to solve it? Previously, I used chrome 103 and changed it to 104 but still got the same error. It seems the error only occurs when changing into the new tab.
I had recently started learning automation with python using selenium. I had installed chromedriver but when i run the code chrome displays no output. My code:
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("www.wikipedia.com")
Output
Output :
C:\Users\Admin\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/untitled/1.py
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/untitled/1.py", line 5, in <module>
driver.get("www.wikipedia.com")
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=88.0.4324.96)
Please help as I'm unable to proceed.
Thanks!
URL should contain scheme. Simply replace
"www.wikipedia.com"
with
"https://www.wikipedia.com"
I followed this tutorial for Selenium with Python:
So I did the same as the tutorial:
from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://www.youtube.com/')
searchbox = driver.find_element_by_xpath('//*[#id="search-input"]')
searchbox.send_keys('cooking')
But I get this error:
Traceback (most recent call last):
File "C:/ANGUS/DATA_ANALYSIS/WEBSCRAPING/TextXXX.py", line 7, in <module>
searchbox.send_keys('cooking')
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Angus\PycharmProjects\Test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=81.0.4044.138)
How can I fix this?
Another way to do that in order not to use the search is by inserting the query itself.
Code:
your_query = "cooking"
driver.get("https://www.youtube.com/results?search_query=" + str(your_query))
time.sleep(5)
In this way, it is like you are going immediately in the output that you want after searching a specific query of yours. So, let's say that instead of typing cooking, you can .get() to the URL you want by adding your query into this URL.
Using chrome 76.0.3809.132 with chromedriver 76.0.3809.126 the testing browser opens but throws a traceback on the driver.get. It isn't able to fetch the page.
Tried couple of arguments, and tried looking for an older version of Chrome with an older chrome driver, which seems impossible.
from selenium import webdriver
driver = webdriver.Chrome("C:/chromedriver/chromedriver.exe")
driver.get("www.google.com")
Output:
DevTools listening on ws://127.0.0.1:57577/devtools/browser/7494ca24-60fb-4b14-9aed-4f25232b94bd
Traceback (most recent call last):
File "slidingwindow.py", line 5, in <module>
driver.get("www.google.com")
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\projects\python\harvester\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument (Session info: chrome=76.0.3809.132)
Try to insert https://:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="chromedriver.exe")
driver.get("https://www.google.com")
I just installed Splinter, input simple code like below but have error. Can someone help me on this? Thanks.
from splinter import Browser
b=Browser()
url = "http://www.google.com"
b.visit(url)
Error messages:
Traceback (most recent call last): File "", line 1, in
File
"/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/init.py",
line 184, in visit
self.driver.get(url) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 245, in get
self.execute(Command.GET, {'url': url}) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 233, in execute
self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
line 194, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Target URL
www.google.ca is not well-formed. Stacktrace:
at FirefoxDriver.prototype.get (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/driver-component.js:10636)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpsIlz0H/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Try this instead:
from splinter import Browser
with Browser() as b:
b.visit("http://www.google.com")
Docs here: https://splinter.readthedocs.org/en/latest/#sample-code
The method above handles quitting the browser. Your method, also in the docs, should work (it works for me). Try it again, I've noticed I get almost the same error as yours, if my url is "www.google.com". Make sure you have "http://" part.
selenium.common.exceptions.WebDriverException: Message: Target URL
www.google.com is not well-formed