e = document.getElementsByTagName('body')[0].children
for (let i = 0; i < e.length;i++){
console.log(e[i].tagName)
}
在蟒蛇里我试着这么做,但我做不到
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()
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.find_elements_by_xpath("./child::*")
for i in childrens:
print(i.tag_name)
driver.quit()
票数 1
EN
Stack Overflow用户
发布于
2021-12-05 15:53:28
将此转换为Python,以获取父元素中的所有子元素
e = document.getElementsByTagName('body')[0].children
for (let i = 0; i < e.length;i++){
console.log(e[i].tagName)
}