Selenium for Python:如何转储当前页面的HTML [英] Selenium for Python: How to dump current page's HTML

查看:181
本文介绍了Selenium for Python:如何转储当前页面的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用selenium模块,如何转储当前页面的HTML(出于调试目的)?它没有说明如何执行以下操作: http://selenium-python.readthedocs.io/api .html

Using the selenium module, how do I dump the current page's HTML (for debugging purposes)? It doesn't say how to here: http://selenium-python.readthedocs.io/api.html

推荐答案

您可以使用WebDriver属性page_source转储当前页面的HTML内容.

You can dump the current page's HTML content using the WebDriver property page_source.

示例代码段

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://yourfavoriteurl')
if 'interested_string' in driver.page_source:
    print('String matched!')

这篇关于Selenium for Python:如何转储当前页面的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆