Python Forum
Login and download an exported csv file within a ribbon/button in a website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login and download an exported csv file within a ribbon/button in a website
#1
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

[Image: 1SV25.png]

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

[Image: bS1sC.png]

I am successful until the navigating to the url2 site. But couldn't download the csv file. Please suggest me the next few lines of code in python. If it is in python Requests and GET instead of selenium, I highly appreciate it. Thank you


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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Push Button on website cg1980 1 420 Feb-07-2024, 01:25 AM
Last Post: snippsat
  Website scrapping and download santoshrane 3 4,335 Apr-14-2021, 07:22 AM
Last Post: kashcode
  Cant Download Images from Unsplash Website firaki12345 1 2,306 Feb-08-2021, 04:15 PM
Last Post: buran
  Download a link that re-directs to a login page justanotherpythonnoob 1 2,713 Oct-23-2020, 03:27 PM
Last Post: Aspire2Inspire
  Get element (ID) from website to login Olimpiarob 4 4,277 Jul-28-2020, 01:20 PM
Last Post: Martinelli
  Python Webscraping with a Login Website warriordazza 0 2,609 Jun-07-2020, 07:04 AM
Last Post: warriordazza
  Cannot download latest version of a file TheTechRobo 3 2,303 May-20-2020, 08:33 PM
Last Post: TheTechRobo
  Create .exe file for Python flask website. vintysaw 4 19,281 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button Webtest 4 8,507 Aug-20-2019, 04:03 PM
Last Post: johnmina
  Login to website kapibara 4 3,573 Jul-27-2019, 02:40 PM
Last Post: kapibara

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020