Issue
noob here. Im trying to login to this site odoo.com with python but it isnt working. There is no evidence that im logged in (im getting 'none' from the print statement, this means the data im expecting if i were logged in isnt there) and i cant figure out why.
I think it has something to do with the 'onsubmit' in the form.
Here is my code
from cred import password, login
import requests
from bs4 import BeautifulSoup as bs
headers = {
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Origin': 'https://www.odoo.com',
'Referer': 'https://www.odoo.com/web/login',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
}
def get_csrf():
#get csrf_token
r = s.get('https://www.odoo.com/web/login')
soup = bs(r.content,'html.parser')
g = soup.head.script.text
g = g.split('\"')
csrf_token = g[1]
return csrf_token
with requests.Session() as s:
csrf_token = get_csrf()
data = {
'csrf_token': csrf_token,
'login': login,
'password': password,
'redirect': ''
}
r = s.post('https://www.odoo.com/web/login', headers=headers, data=data)
re = s.get('https://www.odoo.com/my/databases')
soup = bs(re.content,'html.parser')
print(soup.find('div',{'class':'odoo-oe-databases'}))
any help is appreciated
Solution
You can do it easy with playwright. Put your login and password.
If you want to use it in headless mode put headless=True.
There you have playwright documentation: https://playwright.dev/python/docs/intro
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.webkit.launch(headless=False)
baseurl = "https://www.odoo.com/web/login"
page = browser.new_page()
page.goto(baseurl)
page.fill('#login', 'login email')
page.fill('#password', 'your password')
page.click("button[type='submit']")
elementHandler = page.wait_for_selector(".oe_database_information")
print("Database text: " + elementHandler.text_content())
print("Database all html: " + elementHandler.inner_html())
# print(page.content())
browser.close()
Be carefully, when i did a lot of request, they ban me for one minute.
I hope i was able to help you.
Answered By - MeT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.