G
G
GreenX52020-06-14 11:47:40
Python
GreenX5, 2020-06-14 11:47:40

Is it possible to call a page's html script from a variable in Python?

Opening a local html page with a browser driver is not a problem. And how to write the page into a variable so as not to produce files?
Is it clear now:

from selenium import webdriver

options = webdriver.ChromeOptions()
browser = webdriver.Chrome(options=options)
browser.get('file:///C:/page.html')

How about something like this?
from selenium import webdriver

page = '''...html_скрипт...'''

options = webdriver.ChromeOptions()
browser = webdriver.Chrome(options=options)
browser.get(page)


I tried to enclose in triple-single quotes, swears ...

File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)

InvalidArgumentException: invalid argument
(Session info: chrome= 83.0.4103.97)


in triple quotes, all quotes of the hml script are ignored, and it seems like line breaks, but something does not work ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-14
@GreenX5

driver.get('data:text/html;charset=utf-8,{}'.format(page))

D
Dmitry, 2020-06-14
@LazyTalent

page = browser.get('file:///C:/page.html').page_source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question