How do I solve this Selenium.common.exceptions.WebDriverException error? - python

I got an WebDriverException error, saying that chromedriver.exe needs to be in path, but as you see in the second picture, I have already done that. I am also having trouble figuring out the "unknown error: DevToolsActivePort file doesn't exist"). Attached is the error. Right now I am using this website (https://christophegaron.com/scraping-linkedin-posts-with-selenium-and-beautiful-soup/) to download Chrome Driver and Selenium to my laptop (I already have BeautifulSoup on my laptop so I don't need that one). Also, I have both Ubuntu and Linux, so I am open to using either to solve my issue. I am also using Python 3.8.5, Ubuntu 20.04.2, Chrome version 91, and Linux version 4.4.0.
Also if anyone has any tips regarding how to scrape LinkedIn posts that would be amazing!
picture of the errors/exceptions
picture of code

Thanks for your help! I found that my error was that I was using Ubuntu on a Linux machine (as a VM), when I should have just ran the Chromium program on a natural machine.

Related

Webscraping with requests_html but it says a chromium file is missing

I trying to web scrape using requests-html but it returns an error saying there is a missing file even though I pip install requests-html and it said all req fulfilled. how do I get around this.
from requests_html import HTMLSession
import time
url = 'https://soundcloud.com/jujubucks'
s = HTMLSession()
r = s.get(url)
r.html.render()
songs = r.html.xpath('//*[#id="content"]/div/div[4]/div[1]/div/div[2]/div/div[2]', first=True)
print(songs)
this produces a sxstrace error.
OSError: [WinError 14001] The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or use the command-line
sxstrace.exe tool for more detail
apparently this is the missing file according the event log but I dont know where to get it.
Activation context generation failed for "C:\Users\houst\AppData\Local\pyppeteer\pyppeteer\local-chromium\588429\chrome-win32\chrome.exe". Dependent Assembly 71.0.3542.0,language="*",type="win32",version="71.0.3542.0" could not be found. Please use sxstrace.exe for detailed diagnosis.
I came here with the same question, but the only answer didn't apply to me. My win10x64 PC has 5 versions of python, 4 installed via anaconda and python 3.10 installed via the microsoft store. Debugging the process in vscode using the MS store version... with pip install requests-html installed for that version of python only.
VScode stack trace showed that subprocess.py failed to launch a subprocess.
Windows event viewer showed a failed attempt to launch chrome.exe in:
C:\Users\username\AppData\Local\pyppeteer\pyppeteer\local-chromium\588429\chrome-win32
Windows search showed that chrome.exe - which was downloaded and extracted automatically the first time an attempt was made to call response.html.render() - was actually located at:
C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\Local\pyppeteer\pyppeteer\local-chromium\588429\chrome-win32
As a work around, and although I've no idea why the issue occured, I moved the chrome-win32 directory to the location expected, and found that chrome ran the javascript on the page and returned html correctly.
requests_html depends upon pyppeteer but it seems your pypeteer has not installed chromium completely. Try installing chromium manually, just activate your environment containing pyppeteer and run pyppeteer-install.exe.

Chromium Edge 91 on a Windows 10 crashes

I am trying to run a simple script to open up a google page on Chromium Edge using Python.
What I have so far is
Import selenium
From selenium import webdriver
Path= “..../msedgedriver.exe”
Driver= webdriver.Edge(executable_path=path)
Driver.get(https://google.com)
Got below error:SessionNotCreatedEcception:session not created from tab crashed(Session info:MicrosoftEdge=91.0.864.41)
Tried several things and searched online but no luck yet.Any help will be much appreciated!
There are some problems in the code you provide, I fixed them and tested it, and it works well. My Edge Version is 91.0.864.41 (Official build) (64-bit).
Below is my sample code and you can also try:
import selenium
from selenium import webdriver
path= "D:\\webdriver\\msedgedriver.exe"
driver= webdriver.Edge(executable_path=path)
driver.get("https://www.google.com/")
Please note to modify the path to you owns and use the absolute path of the WebDriver.
I think it may just be a code problem that causes the error.
If the problem persists, can you please provide more information? Such as what version of selenium are you using and what operating system are you using?

Python Selenium execute_script jQuery Error and Discrepencies Between OSs

I'm using Selenium with Python (3.5) to programmatically explore a site. One step of this exploration includes scrolling to the bottom of a given page, and I have chosen to do so with jQuery as such where driver is the webdriver object and scrollloadtime is the set amount of time I want the scrolling to take:
driver.execute_script("$('html, body').animate({scrollTop: $(document).height() - $(window).height()}, %s);" % scrollloadtime)
This is where things get weird. When I run this code in a test environment (VM running Kali Linux), I have no issues with this -- I've never once had a problem with this line running in this environment.
However, when I attempt to run the exact same code with the exact same package versions (which I have listed below) on the exact same webpage inside a docker container running Debian Stretch, I get the following error:
Message: TypeError: $(...).animate is not a function
I'd like to figure out why this is happening rather than just a workaround. It's driving me insane!
I'm certainly no jQuery expert, but from the research I've done on the above error this normally occurs when either an old and minimized jQuery version is being used. What I can't figure out myself is how that solution then ties into Selenium or even Python itself.
Things I have tried, to no avail:
Installed jquery-related packages that exist on my test environment that did not exist within the docker image, on the docker image (i.e. all libjs-jquery* packages).
Attempted to inject jQuery into the page before running the script which triggers DDoS security. (Additionally, this shouldn't be necessary because the jQuery script worked without any injection in the test environment)
Attempted to exchange the initial $('html, body') with a defined variable (var x = document.getElementsByTagName('html')[0]; x.animate(...), though I will be the first to admit that I might not have done so correctly
Versions:
Python 3.5
Selenium (Python) 3.141.0
Geckodriver 0.24.0
Firefox ESR 68.1.0
Debian Stretch and Kali Linux
Any assistance or troubleshooting guidance would be greatly appreciated. Let me know if I can provide any additional information.

Python, Selenium how to ignore shader_cache error?

I keep getting errors like this when running my script (it uses chromedriver):
[15796:2516:0519/121100.926:ERROR:platform_sensor_reader_win.cc(242)] NOT IMPLEMENTED
Is there an easy way just to ignore these errors because as far as I can tell they're not causing anything but it spams the log up a bit?
It actually isnt an issue with chromedriver but rather with chrome v63 or higher. Chrome v63 has bugs in its ShaderCache which is causing this. The easiest fix is downgrading to chrome v60-61 and using chromedriver v2.33 Worked for me. this is the 'Google Chrome Older Versions' :https://www.slimjet.com/chrome/google-chrome-old-version.php
,and this is the chrom driver Mirror:http://npm.taobao.org/mirrors/chromedriver/
Hope that resolves your problem

Anaconda Selenium issues with webdriver

I have been struggling to figure out why I keep getting errors trying to use selenium. I'm using a local install of anaconda3 on my /home/user unix drive at the company I work for. I already pip installed selenium, seemingly without issue, but when I try the following:
from selenium import webdriver
driver = webdriver.Firefox()
it fails with the following message:
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
I've tried downloading the most current chromedriver and trying with that, I've tried installing another gecko-driver, I've tried all kinds of things. But nothing is working. I'm happy to provide any amount of additional information, I just want to get this off the ground at some point...
Thank you!
from selenium import webdriver
path = r'C:\yourgeckodriverpath\geckodriver.exe'
driver = webdriver.Firefox(executable_path=path)
Alright, through a combination of the responses to this question, I have figured out what (I think) went wrong. I was using a linux anaconda install on my company's servers, which (I believe) meant my python had no access to a browser driver. The solution was sadly to install anaconda locally, manually download/unzip/install selenium and geckodriver, and then make sure I pass the whole "executable_path=path" parameter to the Firefox method. This didn't work for Chrome for some reason, which I'll assume has something to do with the unchangeable security specifications on my work machine. If any part of this doesn't sound right, feel free to chime in and shed more light on the issue. Thanks!

Categories