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?

2
  • 1
    Use the Chrome dev tools > Network tab. Click on the CSV button and see where the CSV comes from. Commented Aug 17, 2020 at 22:08
  • Perfect! Nice little trick, was able to get the api endpoint from this Commented Aug 17, 2020 at 22:15

2 Answers 2

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

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

Comments

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.

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.