python 使用selenium时如何获取页面源代码
使用Selenium时,可以使用page_source属性来获取当前页面的源代码。例如:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.example.com")
# 获取页面源代码
page_source = driver.page_source
# 打印页面源代码
print(page_source)
driver.quit()
在这个例子中,我们使用了Firefox浏览器驱动,并访问了http://www.example.com。然后使用page_source属性获取页面源代码,最后打印出来。注意,在使用完Selenium之后,需要调用quit()方法来关闭浏览器并释放资源。
原文地址: http://www.cveoy.top/t/topic/fJj2 著作权归作者所有。请勿转载和采集!