1

So there is a button on a webpage that downloads a csv file after clicking it. In the past I have used selenium to do this, but given the current application of this script being ran on databricks I'd rather not use a web driver. However, when I inspect the button I see no URL or a JS function call. Here is what the html looks like:

<button id="exportReport" class="button">
                    Export Report                   
                </button> == $0

I would link the webpage, but it requires a log in. Is there any way I can simulate clicking this button via requests, mechanize, or beautiful soup?

Marc
  • 123
  • 1
  • 4
  • 17

2 Answers2

3

Copying my comment to the answer:

Use the Chrome dev tools (F12) > Network tab. Click the button on the web page to see where the CSV comes from:

Chrome Tools Network Tab

Mike67
  • 11,175
  • 2
  • 7
  • 15
0

try with mechanize:

import mechanize

br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_equiv(False)
br.set_handle_refresh(False)
br.addheaders = [('User-agent', 'Mozilla/5.0')] 

url = 'https://www.your_url'
br.open(url, timeout=10.0)

# If exist any form
br.select_form(nr= 0)
br.form['name_of_form']=str('text_to_search')

# click on the button and saved it into a variable
data = br.submit()

Another way would be to try with Selenium, in case it is a javascript button:

data=browser.find_element_by_xpath("//input[@id='exportReport']")
data=browser.execute_script("arguments[0].click();", data)

I hope you have success.

aKratos
  • 191
  • 10