我怎样才能把这个JavaScript变成Python,从父元素中获得所有子元素?
这个脚本通过控制台从google.com网站获取所有元素
e = document.getElementsByTagName('body')[0].children
for (let i = 0; i < e.length;i++){
console.log(e[i].tagName)
在Python中我试图这样做,但我不能
import time
import requests
import pandas as pd
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox import options
from selenium.webdriver.firefox.options import Options
option = Options()
option.headless = True
driver = webdriver.Firefox(executable_path=r'C:\geck\geckodriver.exe')
driver.get('https://www.google.com.br/')
body = driver.find_element_by_tag_name('body')
childrens = body.childrens
for i in childrens:
print(i.tagName)
driver.quit()
用于安装软件包的命令。
pip install pandas
pip install bs4
pip install selenium
pip install requests
如何用python从body标签中获取元素名称?