Python Selenium访问HTML源 [英] Python Selenium accessing HTML source
本文介绍了Python Selenium访问HTML源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Selenium模块和Python在变量中获取 HTML 源?
How can I get the HTML source in a variable using the Selenium module with Python?
我想做这样的事情:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://example.com")
if "whatever" in html_source:
# Do something
else:
# Do something else
我该怎么做?我不知道如何访问HTML源.
How can I do this? I don't know how to access the HTML source.
推荐答案
You need to access the page_source
property:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://example.com")
html_source = browser.page_source
if "whatever" in html_source:
# do something
else:
# do something else
这篇关于Python Selenium访问HTML源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文