Python Forum
Using python requests module and BS4 to login on an Wordpress based website - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Using python requests module and BS4 to login on an Wordpress based website (/thread-8080.html)



Using python requests module and BS4 to login on an Wordpress based website - apollo - Feb-06-2018

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> 
finally see also

  File "w1.py", line 1, in <module>
    import requests
ImportError: No module named requests
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?


RE: Using python requests module and BS4 to login on an Wordpress based website - metulburr - Feb-06-2018

pip appears to be installing to python3.4 So now the question is what version of python are you running when you execute
python w1.py
run and tell us the output of
python -V