2 回答
TA贡献2036条经验 获得超8个赞
您也可以避免使用硒,并直接从API中获取硒。您需要做的唯一部分是解析json响应:
import requests
import pandas as pd
url = 'https://forecast.vassarlabs.com/api/commanddashboard/getdashboarddata/RAINFALL/24%20Hrs/District'
jsonData = requests.get(url).json()
jsonData = jsonData['Andhra Pradesh']
results = pd.DataFrame()
for k,v in jsonData.items():
row = pd.DataFrame(v['rainfallDataMap']).head(1)
row['District'] = k
results = results.append(row, sort=False).reset_index(drop=True)
输出:
print (results.to_string())
05:30-11:30 11:30-17:30 17:30-23:30 23:30-05:30 24 Hrs District
0 0.0 0.44 0.00 0.0 0.44 East Godavari
1 0.0 0.00 0.00 0.0 0.00 Anantapur
2 0.0 0.00 0.00 0.0 0.00 Kadapa
3 0.0 0.00 0.00 0.0 0.00 Nellore
4 0.0 0.07 0.00 0.0 0.07 West Godavari
5 0.0 0.00 0.00 0.0 0.00 Srikakulam
6 0.0 0.00 0.00 0.0 0.00 Kurnool
7 0.0 0.00 0.00 0.0 0.00 Chittoor
8 0.0 0.00 0.00 0.0 0.00 Krishna
9 0.0 1.05 0.00 0.0 1.05 Visakhapatnam
10 0.0 0.00 0.00 0.0 0.00 Prakasam
11 0.0 0.12 0.00 0.0 0.12 Total
12 0.0 0.21 0.01 0.0 0.22 Vizianagaram
13 0.0 0.00 0.00 0.0 0.00 Guntur
TA贡献1804条经验 获得超8个赞
from selenium import webdriver
import pandas as pd
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)
driver.implicitly_wait(10)
driver.get("https://forecast.vassarlabs.com/")
myDynamicElement = driver.find_element_by_css_selector(
".fa-list").click()
df = pd.read_html(driver.page_source)[1]
pd.DataFrame(df).to_csv("result.csv", index=False)
driver.quit()
输出:在线检查
添加回答
举报