2016-09-04 5 views
-2

ちょっと私には、以下のWebサイトからの気象データを解析する:あなたは、あなたが任意のインドの都市の名前を入力して、あなたがヒットしたときに終了して行くことができます検索バーを持って観察する場合http://www.indiaweather.gov.in天候のウェブサイトからのデータを解析できません

その都市の気象データを含むページに表示されます。

都市の名前を入力できるスクリプトを教えてもらえますか?都市の気象データが表示されますか?

データの解析方法がわかりませんでした。

ありがとうございます!

+0

ギッターに私を見つけるこの私のnickanmeを行う方法を教えてくれます:dexax –

+0

@Vin、あなたは見当がつかない場合、あなたは多分あなたのためにそれを行うには、開発者を雇う必要があります。 –

答えて

-1

美しいスープを使用できます。特定のhtmlタグ間であなたの望むデータを取得する。自分でやりたいのであれば、サイトのapiを呼び出してデータを投稿することができます。最初のインストール要求。 pip install requestsその後、

import re 
import requests 


# the data is between align="left"><font size="3px"> and </font> in each specific part so we use re to find it 
def find_data(line): 
    return re.search('align="left"><font size="3px">(.*?)</font>', line).group(1) 

params = { 
    'tags': city_name, 
    'submit': 'Go' 
} 

response = requests.post('http://www.indiaweather.gov.in/?page_id=942', data=params).content.splitlines() 

try: 
    current_temp = find_data(response[357]) 
    max_temp = find_data(response[362]) 
    min_temp = find_data(response[369]) 
    last_day_rainfall = find_data(response[376]) 
    current_wind_direction = find_data(response[382]) 
    current_wind_speed = find_data(response[389]) 
    current_dew_point = find_data(response[396]) 
    current_sea_level_pressure = find_data(response[403]) 
    print(current_temp, max_temp, min_temp, last_day_rainfall, current_wind_direction, current_wind_speed, 
      current_dew_point, current_sea_level_pressure) 

except IndexError: 
    print('No Info Found For %s' % params['tags']) 
+0

htmlの解析に正規表現を使用したり、使用したりしないでください。 –

+0

@PadraicCunningham私の間違いを知らせてくれてありがとう:) – Juggernaut

+0

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 –

関連する問題