Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import requests
- import os
- from urllib.parse import parse_qsl, urljoin, urlparse
- loginurl='https://idp.issdc.gov.in/auth/realms/issdc/protocol/openid-connect/auth?response_type=code&client_id=Pradan&redirect_uri=https%3A%2F%2Fpradan.issdc.gov.in%2Fch2%2Fprotected%2Fbrowse.xhtml?id%3Dtmc2&state=bb4349bc-2156-4896-b915-9c64f0209ba8&login=true&scope=openid'
- # theurl= 'https://pradan.issdc.gov.in/ch2/protected/downloadData/POST_OD/isda_archive/ch2_bundle/cho_bundle/nop/ohr_collection/data/calibrated/20220129/ch2_ohr_ncp_20220129T0150171705_d_img_d18.zip'
- username = 'IITP_MID'
- password = 'Iitisro@'
- import requests
- from requests.auth import HTTPBasicAuth
- from bs4 import BeautifulSoup
- login_url = loginurl
- data = {
- 'username': 'IITP_MID',
- 'password': 'Iitisro@'
- }
- # with requests.Session() as s:
- cookies = {
- 'JSESSIONID': '074bc21e370439db8131a256ac0c',
- 'OAuth_Token_Request_State': '607c02d1-3279-41b3-9d72-1668b89b1599',
- }
- headers = {
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
- 'Accept-Language': 'en-US,en;q=0.9',
- 'Cache-Control': 'max-age=0',
- 'Connection': 'keep-alive',
- # 'Cookie': 'JSESSIONID=074bc21e370439db8131a256ac0c; OAuth_Token_Request_State=607c02d1-3279-41b3-9d72-1668b89b1599',
- 'Sec-Fetch-Dest': 'document',
- 'Sec-Fetch-Mode': 'navigate',
- 'Sec-Fetch-Site': 'same-site',
- 'Sec-Fetch-User': '?1',
- 'Upgrade-Insecure-Requests': '1',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
- 'sec-ch-ua': '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"Windows"',
- }
- response = requests.get('https://pradan.issdc.gov.in/ch2/protected/browse.xhtml?id=tmc2', cookies=cookies, headers=headers)
- # print(response.text)
- soup=BeautifulSoup(response.content,"html.parser")
- element_by_id=soup.find("tbody",{"id":"tableForm:lazyDocTable_data"})
- print(element_by_id)
- download = "";
- for a in element_by_id.find_all('a', href=True):
- print("Found the URL:", a['href'])
- download = a['href']
- download = "https://pradan.issdc.gov.in" + download
- print("Downloading: " + download)
Advertisement
Add Comment
Please, Sign In to add comment