Jump to content

login to a Wordpress based website using python's request module and beautifulsoup4.


dil_bert

Recommended Posts

dear community,

I'm trying to login to a Wordpress based website using python's request module and beautifulsoup4.
It seems like the code fails to sucessfully login. Also, there is no csrf token on the website. How do I sucessfully login to the website?
 

import requests
import bs4 as bs
with requests.session() as c:
    link="https://gpldl.com/sign-in/" #link of the webpage to be logged in
    initial=c.get(link) #passing the get request
    login_data={"log":"*****","pwd":"******"} #the login data from any account on the site. Stars must be replaced with username and password
    page_login=c.post(link, data=login_data) #posting the login data into the link
    print(page_login) #checking status of requested page
    page=c.get("https://gpldl.com/my-gpldl-account/") #requesting source code of logged in page
    good_data = bs.BeautifulSoup(page.content, "lxml") #parsing it with BS4
    print(good_data.title) #printing this gives the title that is got from the page when accessed from an logged-out account

 
 
i got back:

martin@linux-3645:~/dev/python> python w1.py
Traceback (most recent call last):
  File "w1.py", line 1, in <module>
    import requests
ImportError: No module named requests


well: Requests is not a built in module (does not come with the default python installation), so we will have to install it:

OSX/Linux

i used this command: 

Use $ sudo pip install requests 

since i have pip installed

Alternatively we can also use

sudo easy_install -U requests

if we have easy_install installed.

 

martin@linux-3645:~/dev/python> sudo pip install requests
Requirement already satisfied: requests in /usr/lib/python3.4/site-packages
martin@linux-3645:~/dev/python>

so what can i do now?


 

Link to comment
Share on other sites

hello

 

well it seems that i run into some kind of confusion.

 

note: i am on opensuse 42.3 -

 

i have python 2 on board -

 

see:  this information is available in the sys.version string in the sys module:

>>> import sys
 

martin@linux-3645:~/dev/python> python sys.py
2.7.13 (default, Jan 03 2017, 17:41:54) [GCC]

well - this is confusing - since i have modules imported that are attached to Version 3... (see above)


  File "w1.py", line 1, in <module>
    import requests
ImportError: No module named requests

hmm - i have to muse - what i can do now....:

 

 

 

 

perhaps force the system to use version 3....  - this can be done so.

 

python2 in terminal or python3 in terminal

 

 

otherwise / furthermore i could tell in sheebang to use pyton 3 ...

 

what do you suggest!?

Link to comment
Share on other sites

good day dear experts,

3.4.6 (default, Mar 22 2017, 12:26:13) [GCC]
martin@linux-3645:~/dev/python> python3 w1.py
<Response [200]>
<title>GPLDL - WordPress GPL Club Membership for free!</title>
martin@linux-3645:~/dev/python>

well does this mean;

200 OK. The request has succeeded

i will have a closer look later the day. note: the internet is pretty slow

 

here....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.