薑也是南投的重要產物,前十名鄉鎮就有4個。
程式:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import requests from bs4 import BeautifulSoup import pandas as pd my_data = {'accountingyear': '109', 'item': '03', 'crop':'441', 'city':'0008', 'desc_asc':'desc'} r = requests.post("https://agr.afa.gov.tw/afa/pgcropmeaqty_all.jsp",my_data ) soup = BeautifulSoup(r.text, 'lxml') result = soup.find("div", class_="DivRestTbl") dfs = pd.read_html(str(result)) df = dfs[0] for item in range(1, 11): print("薑種植面積排第{}名的鄉鎮是{}, 佔合全國收量的{}%".format( item, df.at[item+2,0], int(df.at[item+2,4])/int(df.at[2,4])*100)) |
沒有留言:
張貼留言