0

I want to get a local html source through selenium.

from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome('/usr/local/bin/chromedriver2')
driver.get("test.html")
html = driver.page_source
bsObj = BeautifulSoup(html)

However, this error occurs.

Traceback (most recent call last):
 File "test.py", line 4, in <module>
 driver.get("test.html")
File "/Users/seula/miniconda3/lib/python3.7/site- 

packages/selenium/webdriver/remote/webdriver.py", line 333, in get self.execute(Command.GET, {'url': url}) File "/Users/seula/miniconda3/lib/python3.7/site- packages/selenium/webdriver/remote/webdriver.py", line 321, in execute

self.error_handler.check_response(response)

  File "/Users/seula/miniconda3/lib/python3.7/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=79.0.3945.130)

1 Answer 1

2

You need to tell the driver it's a file and not url

driver.get(r'file:\C:\folder\test.html')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.