Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python中的Selenium Webdriver实例获取文本_Python_Selenium_Selenium Webdriver - Fatal编程技术网

从python中的Selenium Webdriver实例获取文本

从python中的Selenium Webdriver实例获取文本,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,如何获取Webdriver实例的所有文本 获取Webelement的文本非常简单,例如: 或 然而,为了从Webdriver元素获得它,我没有找到类似的解决方案。我刚刚想出了以下两步方法: driver.get(url) driver.find_element_by_tag_name('body').text 但在我看来,必须有更好的方法……您可能会尝试: driver.get(url) page_source = driver.page_source # This gives you a

如何获取Webdriver实例的所有文本

获取Webelement的文本非常简单,例如:

然而,为了从Webdriver元素获得它,我没有找到类似的解决方案。我刚刚想出了以下两步方法:

driver.get(url)
driver.find_element_by_tag_name('body').text
但在我看来,必须有更好的方法……

您可能会尝试:

driver.get(url)
page_source = driver.page_source  # This gives you a 'str' containing the html source
print(page_source)
另见

如果您需要解析
页面\u源代码
BeautifulSoup4也是一个有用的工具。

您可能会尝试:

driver.get(url)
page_source = driver.page_source  # This gives you a 'str' containing the html source
print(page_source)
另见

如果需要解析
页面\源代码
BeautifulSoup4也是一个有用的工具

driver.get(url)
page_source = driver.page_source  # This gives you a 'str' containing the html source
print(page_source)