# Mechanize - problem with downloading csv file

**URL:** <https://www.ruby-forum.com/t/mechanize-problem-with-downloading-csv-file/161227>\
**Category:** Ruby\
**Created:** [February 24, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/mechanize-problem-with-downloading-csv-file/161227 "2009-02-24T13:47:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhransu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@subhransu](https://www.ruby-forum.com/u/subhransu)\
**Post date:** [February 24, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/mechanize-problem-with-downloading-csv-file/161227/1 "2009-02-24T13:47:12Z")

</div>

Hi,

I am trying to download the past call details from ATnT site  
in csv format.

It requires to select the bill period and click on a radio button.  
Then clicking on “Submit” link downloads the call summary for  
that period.

I tried to do it in mechanize in the following way, but it download  
the src of the page in stead of downloading the actual CSV file.

# get the download page

page\_download = agent.get "  
[https://www.wireless.att.com/view/billPayDownloadDetail.doview?execdownloadPage=true](https://www.wireless.att.com/view/billPayDownloadDetail.doview?execdownloadPage=true)  
"

# get the form for bill\_period and select a bill period

bill\_period\_form = page\_download.forms[2]  
bill\_period\_form.field.options[2].select

# click on the csv radio button

download\_format\_form = page\_download.forms[3]  
download\_format\_form.radiobuttons[1].click

# click on the submit link that downloads the csv file.

download\_file = agent.click download\_page.search(“a”)[41]  
download\_file.save\_as(“\<path\_to\_file\>.csv”)

The problem I am facing in the above code is:

- Doesn’t do anything special after selecting a particular bill period  
from  
the select options.
- Download the page source in stead of downloading the actual csv file.

Can you suggest something? Am I missing something here?

Thanks,  
Subhransu
