2015-10-13 30 views
1

網頁源顯示:如何刮取來自下拉列表的數據?

<div class="content"> 

    <h2 class="branded">Fixtures</h2> 

<div class="mobile-select gameweek-selector-div clearfix"> 
    <select class="gameweek-selector" > 
     <option value="-1">All Season</option> 

      <option value="1">Matchweek 1</option> 

      <option value="2">Matchweek 2</option> 

      <option value="3">Matchweek 3</option> 

    </select> 
</div> 

我想,當我選擇這些選項之一湊數據值 問題是該網站的網址並沒有改變它只是用來加載內容

+0

分開你將如何解析的東西是永遠不會有???選項甚至沒有被選中,所以如何通過解析獲得選擇的選項? –

+0

我不確定你在問什麼? –

+0

我剛剛開始與蟒蛇:) http://m.premierleague.com/content/mobile/en-gb/fixtures.html即時通訊試圖讓時間,固定裝置。 –

回答

1

嘗試使用您的瀏覽器的網絡分析器。

當我訪問網站並選擇不同的比賽周時,每次都會發送GET請求。

例如,這裏是1周的請求URL:

http://m.premierleague.com/pa-services/api/football/mobile/competition/fandr/api/gameweek/1.json

...和2周:

http://m.premierleague.com/pa-services/api/football/mobile/competition/fandr/api/gameweek/2.json

通知,到底有多少是所有改變了。您可以輕鬆地循環遍歷每週迭代中的GET請求。

這裏是解決方案的草圖:

import json 
import urllib 

number_of_weeks = 20 
base_url = 'http://m.premierleague.com/pa-services/api/football/mobile/competition/fandr/api/gameweek/' 

for i in range(1, number_of_weeks+1): 
    page = urllib.urlopen(baseurl+str(i)).read() 
    json_content = json.loads(page) 
    ## now you can do something with the data 
相關問題