Python Selenium 访问 HTML 源代码 [英] Python Selenium accessing HTML source
本文介绍了Python Selenium 访问 HTML 源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用带有 Python 的 Selenium 模块在变量中获取 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.
推荐答案
您需要访问 page_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屋!
查看全文