Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Info web login
#11
You need to make a POST requests to the url defined in action.

Use the names as keys and values as values for your data (fill in what's missing).
Some of those are probably automatically generated, so you'll have to extract them from the original page's source.
Reply
#12
If i look at this,would try to write it like this.
import requests
from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}

params = {
    "username": "your_username",
    "password": "xxxxxxx",
    "option": "com_users",
    "task": "user.login",
    "return": "aW5kZXgucGhwP0l0ZW1pZD0xMDE=",
    "3b75647a02faf65a2052c707aca4fa6b": "1"
}

with requests.Session() as s:
    s.post('http://dls.delonghigroup.com/index.php?lang=it', headers=headers, params=params)
    # logged in! session cookies saved for future requests
    response = s.get('url acess when logged in')
    # Can eg do some parsing
    soup = BeautifulSoup(response.content, 'lxml')
    welcome = soup.find('span', class_="welcome").text
    print(welcome)
This is basic setup when i look at what happens when try to log in to that site,
may need to pares out 3b75647.... which can be unique for each session.
rahuldas Wrote:i wana know that is there any possibility that i can learn online web development and coading with the help of w3 school?
Can learn something,but i think most as me use it sometime as reference eg how was link tag format.
For web-development in Python look into Flask(my favorite) or Django.
Reply
#13
import requests
from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
 
params = {
    "username": "xxxxxx",
    "password": "xxxxxxxx",
    "option": "com_users",
    "task": "user.login",
    "return": "aW5kZXgucGhwP0l0ZW1pZD0xMDE=",
    "dfb484877434ffea31834bc369796d7b": "1" # this value change whit each access requests
}
 
with requests.Session() as s:
    s.post('http://dls.delonghigroup.com/index.php?lang=it', headers=headers, params=params)
    # logged in! session cookies saved for future requests
    response = s.get('http://dls.delonghigroup.com/index.php?option=com_ecart&view=product&id=204215&lang=it')
    
    soup = BeautifulSoup(response.content, 'html.parser')


    print (soup)
I thank you for your help
I modified it to see html of the page.
Unfortunately it does not work because the value that I highlighted changes with each access request
Reply
#14
Quote:"dfb484877434ffea31834bc369796d7b": "1"
where does this value come from?
How do you get it, and is it possible to fetch automatically
Reply
#15
I already do this work through the Excel VBA

here I use this instruction
article = "http://dls.delonghigroup.com/index.php?
ie.navigate article


First I log in from the default browser and then the excel macro that does not require the user and password again.


A solution of this type would be fine, but I do not know how to tell python that the log has already been done via the browser.
Excuse me if I'm not clear

(Nov-27-2018, 12:29 PM)Larz60+ Wrote:
Quote:"dfb484877434ffea31834bc369796d7b": "1"
where does this value come from?
How do you get it, and is it possible to fetch automatically

<form
name="loginform" class="login-form clearfix"
action="http://dls.delonghigroup.com/index.php?option=com_users&amp;view=login&amp;lang=it"
method="post" id="login-form">

<input class="form-control" type="text" name="username" id="user_login" value="" size="20"
placeholder="Nome utente" />
<input class="form-control" type="password" name="password" id="user_pass" value="" size="20"
placeholder="Password" />

<input type="submit" name="" value="Accedi" />


<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" />
<input type="hidden" name="dfb484877434ffea31834bc369796d7b" value="1" /> </form>

the value in bold changes with each request
Reply
#16
I did mention that may need to parse out that value.
You should try to this this yourself.
It can be done like this.
import requests
from bs4 import BeautifulSoup

url = 'http://dls.delonghigroup.com/index.php?lang=it'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
token = soup.find(attrs={"value": "1"})
print(token.get('name'))
Output:
e45d72564cc455fcd22d1fc7e85d71f9
Also this has to be done in same Session,as a new value is generated each time.
Untested it can look like this.
import requests
from bs4 import BeautifulSoup

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}

with requests.Session() as s:
    url = 'http://dls.delonghigroup.com/index.php?lang=it'
    response = s.get(url)
    soup = BeautifulSoup(response.content, 'lxml')
    token = soup.find(attrs={"value": "1"})
    #print(token.get('name'))
    params = {
        "username": "your_username",
        "password": "xxxxxxx",
        "option": "com_users",
        "task": "user.login",
        "return": "aW5kZXgucGhwP0l0ZW1pZD0xMDE=",
        f"{token.get('name')}": "1"
    }
    s.post('http://dls.delonghigroup.com/index.php?lang=it', headers=headers, params=params)
    # logged in! session cookies saved for future requests
    response = s.get('url acess when logged in')
    # Can eg do some parsing
    soup = BeautifulSoup(response.content, 'lxml')
    welcome = soup.find('span', class_="welcome").text
    print(welcome)
Reply
#17
It still does not work.
I found that in the HTML of the page there is this script that generates a token
<script>
var v_userId = 0;
var v_userDivision = 0;
var v_userToken = 'ug7bu3iv2e1395576c0bvrndn5.67162bd6f84cf90f911e118e701974428a105038.';
var v_userLang = 'it-it';
var v_userCountry = '<br />
<b>Notice</b>: Trying to get property of non-object in <b>/var/www/vhosts/dlspro.delonghigroup.com/templates/dls/index.php</b> on line <b>113</b><br />
';
var v_userType = 'u';
</script>

maybe this is the token that has to be inserted
I do not want to create another trouble, you've already been very kind
Reply
#18
It can maybe be used,it's hard for me to test as i don't have access to site.
Can show one with selenium that can be used for more difficult log in problems.
When logged in can also send pages source to a parser if that's needed.
Example this fill fields and push Submit button
from selenium import webdriver
from bs4 import BeautifulSoup
import time

browser = webdriver.Chrome()
url = 'http://dls.delonghigroup.com/index.php?lang=it'
browser.get(url)
user_name = browser.find_element_by_css_selector('#user_login')
user_name.send_keys("Foo")
password = browser.find_element_by_css_selector('#user_pass')
password.send_keys("Bar")
time.sleep(5)
submit = browser.find_elements_by_css_selector('#login-form > input[type="submit"]:nth-child(3)')
submit[0].click()
time.sleep(5)

# Give source code to BeautifulSoup
'''
soup = BeautifulSoup(browser.page_source, 'lxml')
title = soup.select('head > title')
print(title[0].text)
'''
Reply
#19
I tried but I receive this error

Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\Prova12.py", line 9, in <module>
browser.get(url)
File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"924A731AC11BFC6FFBB37CCFAB3B81C7","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
Reply


Forum Jump:

User Panel Messages

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