Login and download an exported csv file within a ribbon/button in a website

Hey Guys,

I am trying to log into a website and download a specific file by using export option within a ribbon

Specifically, I am logging into a primary website url(url1).

After logging into the website, i am navigating to the another url(url2) internally in the same website.

Then my intention is to write a few lines of code, to make it understand that to select the ribbon and export the file as csv and download, where I am stuck at.

Please find the screenshot in blue encircled which is important fyi

And this is the inspect element code to find the appropriate functions ,

I am successful until the navigating to the url2 site. But couldn’t download the csv file. Highly appreciate if the script in GET and POST request.

This is my code so far

#!/usr/bin/python
import requests
import sys
sys.stdout = open("path/logfilenew1.log", "w")
#Fill in your details here to be posted to the login form.
payload = {
    'inUserName': '**********',
    'inUserPass': '**********' }
#Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:
p = s.post('HTTPS://oauth.url1', data=payload)
#print the html returned or something more intelligent to see if it's a successful login page.
print p.text
#An authorised request.
r = s.get('https://url2')
print r.text

OR using selenium

#!usr/bin/python
import sys
sys.stdout =open("path/logfilenew.log", "w")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path='path/chromedriver.exe')#put here the adress of your page
payload = {​​​​​​​
    'inUserName': '**********',
    'inUserPass': '**********'
}​​​​​​​
driver.get('url2', payload)
btn = driver.find_element_by_xpath('/html/body/div[3]/div[3]/ul/a[1]')
btn.click()
df = pd.read_csv('path/res.csv')
print(df.head())
driver.close()