使用Selenium获取渲染页面的当前HTML [英] Get current HTML of rendered page using Selenium

查看:127
本文介绍了使用Selenium获取渲染页面的当前HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获取Facebook应用程序的硒中呈现的html代码.登录后,我进入应用程序页面并使用 time.sleep(20)等待其完全呈现.

I'm strugling to get the rendered html code in selenium of a facebook app. After login I go to the app page and use time.sleep(20) to wait for it to fully render.

我已经尝试了3种解决方案,但都没有巫婆的作品:

I have already tried 3 solutions none of witch works:

self.driver.page_source # This one returns source code
self.driver.find_element_by_xpath('//*').get_attribute('outerHTML')
self.driver.execute_script("return document.getElementsByTagName('html')[0].outerHTML")

我正在使用google chrome驱动程序和python3.只是要清楚.

I'm using the google chrome driver and python3. Just to be clear.

我不清楚什么都不起作用.上面的每一项返回的内容都与我点击检查元素"时显示的内容不同

I wasn't clear about what don't work means. Each one of the above returns a different thing from what is presented when I hit "Inspect Element"

推荐答案

self.driver.find_element_by_xpath("//body").get_attribute('outerHTML')

...并且不要使用time.sleep().使用WebdriverWait,然后等待页面上的唯一元素加载.

...and don't use time.sleep(). Use a WebdriverWait and wait for a unique element on the page to load.

这篇关于使用Selenium获取渲染页面的当前HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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