Bottom Page

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
Quote
#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
nilamo likes this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python tool based on website? zarize 2 298 Mar-21-2020, 02:25 PM
Last Post: zarize
  Scraping problems with Python requests. gtlhbkkj 1 146 Jan-22-2020, 11:00 AM
Last Post: gtlhbkkj
  Parsing based on variables in the website nikos48 3 220 Jan-19-2020, 03:41 PM
Last Post: nikos48
  ModuleNotFoundError: No module named "requests" BushFacts 1 495 Jan-13-2020, 06:49 AM
Last Post: perfringo
  requests problem in python script "content type" abdlwafitahiri 4 293 Dec-29-2019, 02:29 PM
Last Post: abdlwafitahiri
  Create .exe file for Python flask website. vintysaw 4 1,178 Nov-18-2019, 07:56 AM
Last Post: tonycstech
  Post comment on my blog (wordpress) eddienguyen 2 564 Oct-04-2019, 11:25 AM
Last Post: metulburr
  Python-selenium script for automated web-login does not work hectorKJ 2 749 Sep-10-2019, 01:29 PM
Last Post: buran
  HOWTO? Login DSL Modem with Python Requests: need Click "Apply" Button Webtest 4 3,476 Aug-20-2019, 04:03 PM
Last Post: johnmina
  Post comments to Wordpress Blog SergeyLV 1 377 Aug-01-2019, 01:38 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)