第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

BeautifulSoup 在網(wǎng)頁上找不到表格

BeautifulSoup 在網(wǎng)頁上找不到表格

慕村225694 2023-10-26 10:22:35
所以我發(fā)現(xiàn)我的問題,它位于代碼的前面,我最初從另一個數(shù)據(jù)幀中切出了change_details。change_details = gdp_sched_today[[start_date', 'end_date']]change_details.columns = ['Planned Start Date', 'Planned End Date']change_details['Planned Start Date'] = change_details['Planned Start Date'].dt.strftime('%d/%m/%Y %h:%M')change_details['Planned End Date'] = change_details['Planned End Date'].dt.strftime('%d/%m/%Y %H:%M')我可以通過在第一行添加 .copy() 來解決這個問題,確保 Pandas 知道我打算將其設(shè)為副本而不是視圖。change_details = gdp_sched_today[[start_date', 'end_date']].copy()change_details.columns = ['Planned Start Date', 'Planned End Date']change_details['Planned Start Date'] = change_details['Planned Start Date'].dt.strftime('%d/%m/%Y %h:%M')change_details['Planned End Date'] = change_details['Planned End Date'].dt.strftime('%d/%m/%Y %H:%M')如果警告能更清楚地說明觸發(fā)它的原因,那就太好了:)
查看完整描述

2 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗 獲得超10個贊

表存在于iframe您需要iframe先切換才能訪問的內(nèi)部table。


引發(fā)WebDriverWait()等待frame_to_be_available_and_switch_to_it()和下面的定位符。


引發(fā)WebDriverWait()等待visibility_of_element_located()和下面的定位符。


driver.get("https://learn.microsoft.com/en-us/windows/release-information/")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"winrelinfo_iframe")))

table=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"table.cells-centered")))

您需要導(dǎo)入以下庫。


from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

或者您將下面的代碼與xpath.


driver.get("https://learn.microsoft.com/en-us/windows/release-information/")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"winrelinfo_iframe")))

table=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="winrelinfo_container"]/table[1]')))

您可以將表數(shù)據(jù)進(jìn)一步導(dǎo)入到 pandas 數(shù)據(jù)框,然后導(dǎo)出到 csv 文件。您需要導(dǎo)入 pandas。


driver.get("https://learn.microsoft.com/en-us/windows/release-information/")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"winrelinfo_iframe")))

table=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="winrelinfo_container"]/table[1]'))).get_attribute('outerHTML')

df=pd.read_html(str(table))[0]

print(df)

df.to_csv("path/to/csv")

導(dǎo)入熊貓:pip install pandas


然后添加以下庫


import pandas as pd


查看完整回答
反對 回復(fù) 2023-10-26
?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗 獲得超2個贊

該表位于 內(nèi)部<iframe>,因此BeautifulSoup在原始頁面中看不到它:


import requests 

from bs4 import BeautifulSoup



url = 'https://learn.microsoft.com/en-us/windows/release-information/'

soup = BeautifulSoup(requests.get(url).content, 'html.parser')

soup = BeautifulSoup(requests.get(soup.select_one('iframe')['src']).content, 'html.parser')


for row in soup.select('table tr'):

    print(row.get_text(strip=True, separator='\t'))

印刷:


Version Servicing option    Availability date   OS build    Latest revision date    End of service: Home, Pro, Pro Education, Pro for Workstations and IoT Core End of service: Enterprise, Education and IoT Enterprise

2004    Semi-Annual Channel 2020-05-27  19041.546   2020-10-01  2021-12-14  2021-12-14  Microsoft recommends

1909    Semi-Annual Channel 2019-11-12  18363.1110  2020-09-16  2021-05-11  2022-05-10

1903    Semi-Annual Channel 2019-05-21  18362.1110  2020-09-16  2020-12-08  2020-12-08

1809    Semi-Annual Channel 2019-03-28  17763.1490  2020-09-16  2020-11-10  2021-05-11

1809    Semi-Annual Channel (Targeted)  2018-11-13  17763.1490  2020-09-16  2020-11-10  2021-05-11

1803    Semi-Annual Channel 2018-07-10  17134.1726  2020-09-08  End of service  2021-05-11


...and so on.


查看完整回答
反對 回復(fù) 2023-10-26
  • 2 回答
  • 0 關(guān)注
  • 218 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號