0

I'd like to connect to the website, then go to the account page and get my invoice.

I already some of topics but my script stills not work ...

This is my code. Do you see something wrong ? or I miss something about the connection.

Edit: I tried on another website and it's working, so I think I miss something about the connection of this website.

import requests
from bs4 import BeautifulSoup

payload = {'email_address': 'XXX@gmail.com', 'password': 'XXX'}
url = 'https://www.maxicoffee.com/login.php'
account_url = "https://www.maxicoffee.com/account.php"

with requests.Session() as session:
    session.get(url)
    session.post(url, data = payload)
    account_page = session.get(account_url)
    soup = BeautifulSoup(account_page.content, "html.parser")
    invoice = soup.find("Facture imprimable")
    print(invoice)
auguyon
  • 15
  • 5
  • Are you getting any errors? Because if you could provide any errors, that could help us solve your issue. – Siddharth Dushantha Jul 08 '20 at 07:58
  • When I print the status_code I already have 200. I think the problem come to the connection, after my post I check the page and I can't see something that tells me I'm connected . – auguyon Jul 08 '20 at 08:09
  • You could try adding an user agent to your request: https://stackoverflow.com/a/27652558/9215267 – Siddharth Dushantha Jul 08 '20 at 08:58
  • Thanks, But it's seem like nothing change. I used fake-useragent and add the headers in my GET, then my POST and nothing change. I'm already disconnect after my POST – auguyon Jul 08 '20 at 09:43

1 Answers1

0

I think it may be a good idea if you use the selenium. read the documentation and use it, but I try to say it here how to use it.

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

import os
import time

chromedriver = "driver/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver

driver = webdriver.Chrome(chromedriver)
actions = ActionChains(driver)

username_login = 'XXX@gmail.com'
password_login = 'XXX'


def login(driver , username_login ,password_login):

    login_link = 'https://www.maxicoffee.com/account.php'
    driver.get(login_link)
    time.sleep(5)

    username_input = driver.find_element_by_xpath('that input element xpath')
    password_input = driver.find_element_by_xpath('that input element xpath')

    username_input.send_keys(username_login)
    password_input.send_keys(password_login)

    login_button = driver.find_element_by_xpath('that login button element xpath')
    login_button.click()

Bahram Jannesar
  • 109
  • 1
  • 7