In the following tutorial you will learn that how to login to any website and create a session to navigate in website using Python programming language.
import requests
r = requests.Session()
payload = {
'username':'email@example.com',
'password':'Admin123'
}
r.post('http://localhost/example-website/login', data = payload)
data = r.get('http://localhost/example-website/dashboard').text
print(data)
import requests
from lxml import html
USERNAME = "email@example.com"
PASSWORD = "Admin123"
LOGIN_URL = "http://localhost/example-website/login"
URL = "http://localhost/example-website/dashboard"
def main():
session_requests = requests.session()
payload = {
"username": USERNAME,
"password": PASSWORD
}
session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
result = session_requests.get(URL, headers = dict(referer = URL))
tree = html.fromstring(result.content)
bucket_names = tree.xpath("//div[class=""='repo-list--repo']/a/text()")
print(result.text)
if __name__ == '__main__':
main()
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
USERNAME = "email@example.com"
PASSWORD = "Admin123"
LOGIN_URL = "https://example-website.com/home?v=login"
URL = "https://example-website.com/home"
TableURL = "https://example-website.com/dashboards/XvG2Q7fG";
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options = Options()
options.headless = True
options.add_argument("--headless")
#driver = webdriver.Chrome()
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(URL)
driver.find_element(By.ID, "loginEmail").send_keys(USERNAME)
driver.find_element(By.ID, "formControl").click()
driver.find_element(By.ID, "loginPassword").send_keys(PASSWORD)
driver.find_element(By.ID, "formControl").click()
try:
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, 'create-button-animation-wrapper')))
driver.get(TableURL)
table2 = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, '(//table)[1]/tbody/tr/td')))
table = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, '(//table)[2]'))).get_attribute("outerHTML")
print("Desired url was rendered with in allocated time")
print(driver.page_source)
new_table = pd.read_html(driver.page_source)[0]
print(new_table)
print(table2)
driver.quit()
except TimeoutException:
print("Desired url was not rendered with in allocated time")
print(driver.page_source)
driver.quit()
Note: The above tutorials are created for educational and learning purposes.