0

I am trying to do the following via python:

From this website: http://www.bmf.com.br/arquivos1/arquivos_ipn.asp?idioma=pt-BR&status=ativo

I would like to check the 4th checkbox and then click on Download image.

That is what I did:

import urllib2
import urllib
url = "http://www.bmf.com.br/arquivos1/arquivos_ipn.asp?idioma=pt-BR&status=ativo"
payload = {"chkArquivoDownload3_ativo":"1"}
data = urllib.urlencode(payload)
request = urllib2.Request(url, data)

print request

response = urllib2.urlopen(request)
contents = response.read()

print contents

Does anyone have any suggestions?

1
  • Do we have any suggestions for what? What happens? What do you expect to happen? Commented Sep 23, 2014 at 0:35

2 Answers 2

1

Selenium is a great project, it lets you control a firefox browser with python. Something like this:

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('http://www.bmf.com.br/arquivos1/arquivos_ipn.asp?idioma=pt-BR&status=ativo')

browser.find_element_by_id('chkArquivoDownload3').click()
browser.find_element_by_id('imgSubmeter_ativo').click()

browser.quit()

would probably work.

Sign up to request clarification or add additional context in comments.

Comments

0

Web browsers are a complex collection of components which interact together. Python does not have a web-browser built in (in particular a DOM or Javascript engine) and it is simply downloading a html file which would normally interact with said DOM and javascript in your browser.

The easiest method I foresee:

  1. Pares the string using the python module BeautifulSoup.
  2. Manually make the download request with the information you have parsed.
  3. Save the downloaded image to file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.