Python Forum
A crazy project involving webpage interaction
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A crazy project involving webpage interaction
#1
I have a crazy project in my mind.
Thus is what I what I want my program to do:
It accesses a website "http://www.msmcampuscare.in/Logon/Logon" using get command of Requests module.

There is an option saying "Forgot Password". It should 'click' on it.

Next the website and the user's mobile number. Here I want the program to enter my mobile number which is say '0123456789'.

Website will then show my details. I want these details to be stored in a variable.

To me this project sounds very far-fetched and beyond programming capabilities.

Is it actually possible to design such a program? If yes, please tell me just the basic skeleton of the program.
Reply
#2
That is not far-fetched at all, but we're not going to do it for you. If you give it a try, we can help you through the process though.
Reply
#3
It's not far fetch it's quite common that you write code to access a web-site.
Requests as you mention can be used,
but then have to inspect(eg Chrome/FireFoc Dev Tools) to see what going on when login and try replicate it.
Selenium is an other way to do it,that can be easier.

Example skeleton how it can look in Requests,i took a quick look at login.
The form data that is send when reset is Mobil=0123456789&Type=2
Type is based on first choice so 2 is Student.
You will need Cookie and probably most of header data.
import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0',
     ......
}

cookies = {    
    '__RequestVerificationToken':.....
    ......
}

params = {
    "Mobile":"0123456789", "Type":"2"
}

with requests.Session() as s:
    response = s.post('http://www.msmcampuscare.in/Logon/ResetPassword', headers=headers, cookies=cookies, params=params )
    print(response.text)

    # Authorised request.
    r = s.get('A protected web page url')
    print(r.text)
Reply
#4
(May-19-2018, 12:01 AM)snippsat Wrote: It's not far fetch it's quite common that you write code to access a web-site. Requests as you mention can be used, but then have to inspect(eg Chrome/FireFoc Dev Tools) to see what going on when login and try replicate it. Selenium is an other way to do it,that can be easier. Example skeleton how it can look in Requests,i took a quick look at login. The form data that is send when reset is Mobil=0123456789&Type=2 Type is based on first choice so 2 is Student. You will need Cookie and probably most of header data.
import requests headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0', ...... } cookies = { '__RequestVerificationToken':..... ...... } params = { "Mobile":"0123456789", "Type":"2" } with requests.Session() as s: response = s.post('http://www.msmcampuscare.in/Logon/ResetPassword', headers=headers, cookies=cookies, params=params ) print(response.text) # Authorised request. r = s.get('A protected web page url') print(r.text)

Sir, as I am a newbie, a major portion of this code is incomprehensible to me. However, the '.....' that you have used in the cookies dictionary is being shown as syntax error due to not being present in quotes. Am I missing something here?
Reply
#5
As @snippsat said this is an example skeleton. It's not executable code. The missing parts ( the dots represent one part of them ) you will have to write yourself.
Since you can't recognise that the dots are not Python code I suggest you to start learning Python from the very beginning.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
(May-19-2018, 06:25 AM)wavic Wrote: As @snippsat said this is an example skeleton. It's not executable code. The missing parts ( the dots represent one part of them ) you will have to write yourself. Since you can't recognise that the dots are not Python code I suggest you to start learning Python from the very beginning.
I recognise that some string or integer is supposed to come in the place of those dots. But I don't know what string/integer should take the dots' place
Reply
#7
(May-19-2018, 06:32 AM)apsaditya Wrote: But I don't know what string/integer should take the dots' place
That's problem Wink
I din mention Chrome DevTools and Firefox Developer Tools.
These can be used to look at what's going on when using a web-site.

I you new to all this,you are not starting with an easy task.
This login Mobile reset is not a straight forward login.
I can fill in rest,it may work or not(may need to parse cookie for your session) as mention it's not a straight forward login.
Selenium as mention can be easier,but if not heard of any of this you starting in the wrong end.
import requests

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Host': 'www.msmcampuscare.in',
    'Referer': 'http://www.msmcampuscare.in/Logon/Logon',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0',
    'X-Requested-With': 'XMLHttpRequest',
}

cookies = {
    'ASP.NET_SessionId': 'j5qcmz1bduxsd5ot4slnybre',
    '__RequestVerificationToken': 'OJOQKxvKh_FtI6fmZuNNbI4zaJh3eh7uV1Odh_D_PrORGaPJv74iNQlzNTs9WEcV_zeGxic9B3OZ0WWVTYJyO-c291WoHh2-C7vr7yKZO2s1',
    'chk': 'enable',
}

params = {
    "Mobile":"112234455", "Type":"2"
}

with requests.Session() as s:
    response = requests.post('http://www.msmcampuscare.in/Logon/ResetPassword', headers=headers, cookies=cookies, params=params )
    print(response.text)

    # An authorised request.
    r = s.get('A protected web page url')
    print(r.text)
Reply
#8
(May-19-2018, 11:30 AM)snippsat Wrote:
(May-19-2018, 06:32 AM)apsaditya Wrote: But I don't know what string/integer should take the dots' place
That's problem Wink I din mention Chrome DevTools and Firefox Developer Tools. These can be used to look at what's going on when using a web-site. I you new to all this,you are not starting with an easy task. This login Mobile reset is not a straight forward login. I can fill in rest,it may work or not(may need to parse cookie for your session) as mention it's not a straight forward login. Selenium as mention can be easier,but if not heard of any of this you starting in the wrong end.
import requests headers = { 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Language': 'nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Host': 'www.msmcampuscare.in', 'Referer': 'http://www.msmcampuscare.in/Logon/Logon', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0', 'X-Requested-With': 'XMLHttpRequest', } cookies = { 'ASP.NET_SessionId': 'j5qcmz1bduxsd5ot4slnybre', '__RequestVerificationToken': 'OJOQKxvKh_FtI6fmZuNNbI4zaJh3eh7uV1Odh_D_PrORGaPJv74iNQlzNTs9WEcV_zeGxic9B3OZ0WWVTYJyO-c291WoHh2-C7vr7yKZO2s1', 'chk': 'enable', } params = { "Mobile":"112234455", "Type":"2" } with requests.Session() as s: response = requests.post('http://www.msmcampuscare.in/Logon/ResetPassword', headers=headers, cookies=cookies, params=params ) print(response.text) # An authorised request. r = s.get('A protected web page url') print(r.text)
Thanks friend. I can't figure out what is happening in the script, but it is working flawlessly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best framework for MySQL interaction and Tensorflow / TFLite inference? f_set89 0 526 Nov-23-2023, 04:14 PM
Last Post: f_set89
  this would be silly if it as not driving mr crazy Blue Dog 16 12,673 Oct-27-2016, 10:21 PM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

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