scraping a response from a selected option in dropdown list

后端 未结 2 1004
独厮守ぢ
独厮守ぢ 2020-12-09 14:02

This is an example of a page that lists baseball stats for a selected player, defaulting to the most recent year (2014, soon to be 2015) http://www.koreabaseball.com/Record/

2条回答
  •  醉酒成梦
    2020-12-09 14:33

    An example using Mechanize and Ruby. Modify the form field and submit.

    #!/usr/bin/env ruby
    
    require 'mechanize'
    
    agent = Mechanize.new{ |agent| agent.history.max_size=0 }
    
    agent.user_agent = 'Mozilla/5.0'
    
    url = "http://www.koreabaseball.com/Record/Player/HitterDetail/Game.aspx?playerId=76325"
    
    page = agent.get(url)
    
    form = page.forms[0]
    
    p form['ctl00$ctl00$cphContainer$cphContents$ddlYear']
    
    form['ctl00$ctl00$cphContainer$cphContents$ddlYear'] = 2013
    
    page = form.submit
    
    form = page.forms[0]
    
    p form['ctl00$ctl00$cphContainer$cphContents$ddlYear']
    

提交回复
热议问题