I am trying to use splinter on my mac version 10.12.4 and for that selenium is necessery , I installed everything properly but when i run my code it open a blank chrome window and then i am getting these two error one by one :
first error :
Traceback (most recent call last):
File "/Users/exepaul/Downloads/pythoncrawling/fix.py", line 14, in <module>
browser = Browser('chrome') # open a chrome browser
File "/anaconda/lib/python3.5/site-packages/splinter/browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "/anaconda/lib/python3.5/site-packages/splinter/driver/webdriver/chrome.py", line 34, in __init__
self.driver = Chrome(chrome_options=options, **kwargs)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"6860.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.12.4 x86_64)
second error :
Traceback (most recent call last):
File "/Users/exepaul/Downloads/pythoncrawling/fix.py", line 14, in <module>
browser = Browser('chrome') # open a chrome browser
File "/anaconda/lib/python3.5/site-packages/splinter/browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "/anaconda/lib/python3.5/site-packages/splinter/driver/webdriver/chrome.py", line 34, in __init__
self.driver = Chrome(chrome_options=options, **kwargs)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 295, in execute
response = self.command_executor.execute(driver_command, params)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)
File "/anaconda/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 488, in _request
resp = self._conn.getresponse()
File "/anaconda/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/anaconda/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/anaconda/lib/python3.5/http/client.py", line 266, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
I searched and found this answer which suggested to update your chromedriver so i installed latest chromedriver and update the path in /etc/paths but still i am getting same error , then i tried to understand the error and i thought maybe its because of session so i tried to create session with requests library in python :
import requests
MAX_RETRIES = 20
art="https://www.google.com"
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=MAX_RETRIES)
session.mount('https://', adapter)
session.mount('http://', adapter)
r = session.get(art)
But no luck , I am not getting how to solve this error , my code is :
from splinter import Browser
import pandas as pd
url="https://www.google.com"
browser = Browser('chrome')
browser.visit(url)
search_bar_xpath = '//*[@id="lst-ib"]'
search_bar = browser.find_by_xpath(search_bar_xpath)[0]
search_bar.fill("Tony_stark is Iron_Man")
search_button_xpath = '//*[@id="tsf"]/div[2]/div[3]/center/input[1]'
search_button = browser.find_by_xpath(search_button_xpath)[0]
search_button.click()
search_results_xpath = '//h3[@class="r"]/a'
search_results = browser.find_by_xpath(search_results_xpath)
scraped_data = []
for search_result in search_results:
title = search_result.text.encode('utf8')
link = search_result["href"]
scraped_data.append((title, link))
df = pd.DataFrame(data=scraped_data, columns=["title", "link"])
df.to_csv("links.csv")
I thinks your chromedriver
is not updated Please update it from this link
https://sites.google.com/a/chromium.org/chromedriver/
Also i dont see the path of chromedriver in your code like this
from selenium import webdriver
driver=webdriver.Chrome('D:\\Sankalp_Python\\Python36\\selenium\\chromedriver.exe')