Results 1 to 2 of 2

Thread: Using python requests module and BS4 to login on an Wordpress based website

  1. #1

    Default Using python requests module and BS4 to login on an Wordpress based website

    dear OpenSuse-Experts.


    finally i am happy that python seems to run well on my opensuse-42.3 box.



    what happened: 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?

    Code:
    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:

    Code:
    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 you will have to install it:
    OSX/Linux

    i used this command:
    Code:
    Use $ sudo pip install requests
    if we have pip installed

    Alternatively we can also use
    Code:
     sudo easy_install -U requests
    if we have easy_install installed.

    Code:
    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>
    btw - see this ....:

    Code:
    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? -

    greetings dilbertone
    dilbert ;-)
    Wordpress-development - a Toolset: wpgear.org

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    13,295
    Blog Entries
    2

    Default Re: Using python requests module and BS4 to login on an Wordpress based website

    Just noticed your post and no answers yet...

    An Internet search of "ImportError: No module named requests" returns hits that describe many possible causes... including

    Not installed
    Insufficient version
    Bad path (including the possibility you'have more than one Python installed)
    Not loaded

    You may have to methodically work your way through the many possibilities in the many search hits.
    One good suggestion in the hits that likely automatically addresses many possibilities is to build your app in a virtualenv so that you can have tight control over your python environment.If you do this, I recommend the use of pyenv to enhance managing your virtualenv as described in the following recent Forum thread

    https://forums.opensuse.org/showthread.php/529448-installing-python-3-6-on-leap

    HTH,
    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •