Python Forum
Using python requests module and BS4 to login on an Wordpress based website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using python requests module and BS4 to login on an Wordpress based website
#1
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?
Wordpress - super toolkits a. http://wpgear.org/ :: und b. https://github.com/miziomon/awesome-wordpress :: Awesome WordPress: A curated list of amazingly awesome WordPress resources and awesome python things https://github.com/vinta/awesome-python
Reply
#2
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
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python, Salesforce and WordPress arthurk88 1 665 Nov-21-2023, 10:13 AM
Last Post: Larz60+
  Retrieve website content using Python? Vadanane 1 1,196 Jan-16-2023, 09:55 AM
Last Post: Axel_Erfurt
  Python API for Wordpress Simlock 4 3,680 May-23-2022, 06:47 PM
Last Post: LaverneDejardin
  POST requests - different requests return the same response Default_001 3 1,900 Mar-10-2022, 11:26 PM
Last Post: Default_001
  I want to create an automated website in python mkdhrub1 2 2,311 Dec-27-2021, 11:27 PM
Last Post: Larz60+
  how to run a python script in the background on my wordpress website rockie12us 3 2,655 Aug-13-2021, 05:39 PM
Last Post: ndc85430
  Login and download an exported csv file within a ribbon/button in a website Alekhya 0 2,616 Feb-26-2021, 04:15 PM
Last Post: Alekhya
  Requests module get() incomplete download bobzarm 2 2,486 Feb-17-2021, 04:51 PM
Last Post: bobzarm
  Python to build website Methew324 1 2,195 Dec-15-2020, 05:57 AM
Last Post: buran
  Scraping all website text using Python MKMKMKMK 1 2,051 Nov-26-2020, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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