0

I have a basic webscraper using Selenium which I would like to be able to run on my phone when I am away from my PC. I need information generated by Javascript so Beautiful Soup isn't an option. I found Pydroid which allows me to run Python scripts on my android device but am having issues running Selenium. This is the basic code I'm trying to run

from selenium import webdriver    
import chromedriver_autoinstaller
from selenium.webdriver.chrome.service import Service

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
chromedriver_autoinstaller.install()
driver = webdriver.Chrome(service=Service(),options=options)

I've also tried a suggestion I saw online

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome('./chromedriver', options=options)
driver.get('https://google.com')
driver.quit()

But this dives a Permission denied for the chromedriver folder.

L10Yn
  • 211
  • 2
  • 10
  • How does the folder with the webdriver called? Does the folder name is the same as the file name (`chromedriver`)? – DonnyFlaw Jul 07 '22 at 17:01
  • I think you need the phone hooked up to your computer to do this. (or a Droid emulator) At one point there was a port of HTMLUnit to android though... never used it, and I don't think it's been updated in a while: https://github.com/null-dev/HtmlUnit-Android Your other option would be to use your phone to control your computer at home to run Selenium scripts. – pcalkins Jul 08 '22 at 18:06
  • @pcalkins, yeah I thought that was the case, just checking if someone would somehow know another way. – L10Yn Jul 09 '22 at 08:15
  • @Lifeiscomplex yes, it only asks for File and Media permissions which I've granted and it says No permissions denied. – L10Yn Jul 13 '22 at 17:11
  • @Lifeiscomplex 12. What device have you gotten it working on? – L10Yn Jul 14 '22 at 08:13

1 Answers1

0

I'm not sure if this is the case but you might get Permission denied exception in case chromedriver file is located in the folder with the same name and so when you passed './chromedriver' to webdriver.Chrome call Python tries to execute folder as file.

So make sure you pass file but not folder

DonnyFlaw
  • 581
  • 3
  • 9
  • I tried that, I still get a `Permission denied`. This time it also says `'chromedriver.exe' executable may have wrong permissions. Please see https://chromedriver.chromium.org/home`. I don't see anything there that helps though. – L10Yn Jul 07 '22 at 21:09
  • @L10Yn did you check these answers: [first](https://stackoverflow.com/questions/49787327/selenium-on-mac-message-chromedriver-executable-may-have-wrong-permissions/53577896#53577896), [second](https://stackoverflow.com/questions/47148872/webdrivers-executable-may-have-wrong-permissions-please-see-https-sites-goo/47255840#47255840)? – DonnyFlaw Jul 08 '22 at 07:20
  • Yes I've tried adding the line `os.chmod('./chromedriver/chromedriver.exe', 0o755)` but it still gives the same error – L10Yn Jul 08 '22 at 16:38
  • @L10Yn I believe there is a typo. It should be `os.chmod('./chromedriver/chromedriver.exe', 0755)` – DonnyFlaw Jul 08 '22 at 18:18
  • If I do that I get the error message `SyntaxError: leading zeros in decimal integer literals are not permitted: use an 0o prefix for octal integers`, one of the comments in that post mentioned in Python3 it has to be how I have it there – L10Yn Jul 08 '22 at 20:40