dil_bert Posted February 6, 2018 Share Posted February 6, 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/Linuxi used this command: Use $ sudo pip install requests since i have pip installedAlternatively 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? Quote Link to comment https://forums.phpfreaks.com/topic/306438-login-to-a-wordpress-based-website-using-pythons-request-module-and-beautifulsoup4/ Share on other sites More sharing options...
requinix Posted February 6, 2018 Share Posted February 6, 2018 You tried running the code and it didn't work because the requests module wasn't present. You installed the module. So what happens if you try running the code now? Quote Link to comment https://forums.phpfreaks.com/topic/306438-login-to-a-wordpress-based-website-using-pythons-request-module-and-beautifulsoup4/#findComment-1556050 Share on other sites More sharing options...
dil_bert Posted February 6, 2018 Author Share Posted February 6, 2018 good evening dear requinix i will do a new test later tonight i will keep you poested. greetings dil bert Quote Link to comment https://forums.phpfreaks.com/topic/306438-login-to-a-wordpress-based-website-using-pythons-request-module-and-beautifulsoup4/#findComment-1556086 Share on other sites More sharing options...
dil_bert Posted February 6, 2018 Author Share Posted February 6, 2018 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!? Quote Link to comment https://forums.phpfreaks.com/topic/306438-login-to-a-wordpress-based-website-using-pythons-request-module-and-beautifulsoup4/#findComment-1556090 Share on other sites More sharing options...
dil_bert Posted February 6, 2018 Author Share Posted February 6, 2018 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.... Quote Link to comment https://forums.phpfreaks.com/topic/306438-login-to-a-wordpress-based-website-using-pythons-request-module-and-beautifulsoup4/#findComment-1556092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.