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 仅打印一个';tr';标签插入';t车身';-美丽之群_Python_Selenium_Web_Beautifulsoup_Screen Scraping - Fatal编程技术网

Python 仅打印一个';tr';标签插入';t车身';-美丽之群

Python 仅打印一个';tr';标签插入';t车身';-美丽之群,python,selenium,web,beautifulsoup,screen-scraping,Python,Selenium,Web,Beautifulsoup,Screen Scraping,我试图在“tbody”中只打印一个“tr”标记的内容。 我使用此代码在“tbody”中打印所有的“tr”,但Python不会在Berlin之后打印“tr”。我使用了以下url:。 这是我要完整打印的表格: 从selenium导入webdriver 作为pd进口熊猫 从selenium.webdriver.firefox.options导入选项 选项=选项() options.add_参数('--headless') driver=webdriver.Firefox(options=options

我试图在“tbody”中只打印一个“tr”标记的内容。 我使用此代码在“tbody”中打印所有的“tr”,但Python不会在Berlin之后打印“tr”。我使用了以下url:。 这是我要完整打印的表格:

从selenium导入webdriver
作为pd进口熊猫
从selenium.webdriver.firefox.options导入选项
选项=选项()
options.add_参数('--headless')
driver=webdriver.Firefox(options=options)
司机,快(
"https://interaktiv.morgenpost.de/corona-virus-karte-infektionen-deutschland-weltweit/")
btn=driver.find\u元素\u by\u css\u选择器(
“button.btn.fnktable\uuuu expand”)。单击()
df=pd.read\u html(driver.page\u源)[0]
df.to_csv(“data.csv”,index=False)
driver.quit()

请等待元素位于
HTML
源代码中,好吗?否则,请使用内置的
时间
库,我也投票反对这个问题,因为它完全是重复的。这回答了你的问题吗?我不明白如何让它像我提到的那样工作
from bs4 import BeautifulSoup
from selenium import webdriver 


browser = webdriver.Chrome()
url = "https://interaktiv.morgenpost.de/corona-virus-karte-infektionen-deutschland-weltweit/?fbclid=IwAR0xb7zTV0vstu-sLE3ByHZVSw89HyqjSwMhpfXT23RwcFqR57za2J_l7XQ"
browser.get(url)
soup = BeautifulSoup(browser.page_source, "html.parser")



allStat = {}

table_body = soup.find('tbody')
table_rows = table_body.find_all('tr')

for i in table_rows:
    region = i.find('td', class_ = 'region').get_text()
    confirmed = i.find('td', class_ = 'confirmed').get_text()
    deaths = i.find('td', class_= 'deaths' ).get_text()

    allStat.update({region: [confirmed,deaths]})
print(allStat)