Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Trying to learn request/urllib and other http form modules

Here is a bit of code, basically was stolen and improvised from about 3 or 4 chunks of code. Am I using requests properly?
Right now I figure I'll learn how to login into a webpage then begin doing other small tasks with that knowledge.
Code
import requests
import sys

EMAIL = 'myusername'
PASSWORD = 'mypassword'
URL = 'http://bluelight.org/vb/login.php?do=login'

def main():
    session = requests.session()
    login_data = {
        'loginemail': EMAIL,
        'loginpswd': PASSWORD,
        'submit': 'login',
    }
    try:
        r = session.post(URL, data=login_data)
        r = session.get('http://bluelight.org/vb/private.php?folderid=0')
        print('Login Sucessful!')
    except requests.exceptions.Timeout:
        print("timeout!")
    except requests.exceptions.TooManyRedirects:
        print("To many redirects!")
    except requests.exceptions.RequestException as e:
        print e
        sys.exit(1)


if __name__ == '__main__':
    main()
If you want to do tasks like click button , fill form... Requests won't do it , you'll have to use selenium, cuz it supports javascript.
(Jul 9, 2017 08:57 AM)nizarnizario Wrote:  If you want to do tasks like click button , fill form... Requests won't do it , you'll have to use selenium, cuz it supports javascript.

Thanks this is just the answer I was looking for.

Is this the correct package?
https://pypi.python.org/pypi/selenium
(Jul 9, 2017 09:20 AM)41phafr34k Wrote:  Thanks this is just the answer I was looking for.

Is this the correct package?
https://pypi.python.org/pypi/selenium

Yep, that's the one. Here is some documentation on how to use Selenium: Docs
This is what i get when i try to run the script
Code
spyder@spyder-desktop ~/Desktop $ python sel.py
Traceback (most recent call last):
  File "sel.py", line 6, in <module>
    driver = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.
Does this indicate an issue with my Selenium Package or firefox?

NVM I got it, simply had to re-unpack chromedriver and set the path along with download chromium. Didnt realize it wasn't trying to open FF.
(Jul 9, 2017 08:57 AM)nizarnizario Wrote:  If you want to do tasks like click button , fill form... Requests won't do it , you'll have to use selenium, cuz it supports javascript.

you can do a post request too login.... with requests and be 10x faster then selenium
i like python lua js
Riddle , yup he can do login , but if he needed some kind of action (like bots do: clicking, liking , watching...) he need to do it using selenium :)
(Jul 9, 2017 11:31 AM)nizarnizario Wrote:  Riddle , yup he can do login , but if he needed some kind of action (like bots do: clicking, liking , watching...) he need to do it using selenium :)

Wrong. He can just capture http request and do the same thing via python requests.
[Image: N43q1sy.png]
Wireless Network ,,,, let's assume he wants to create a Adf.Ly bot, he has to wait for the JS timer :) and of course Requests doesn't support that, requests module doesn't work with anything JS-related


Possibly Related Threads...
Thread / Author Replies Views Last Post
[The Brotherhood] by HackersMar 16, 2026 08:20 AM 18 691 Mar 16, 2026 08:20 AM
Last Post: Stanley
[Python] by Bane PopaMar 13, 2020 09:49 PM 5 226 Mar 13, 2020 09:49 PM
Last Post: Nulla Misericordia
[Python] by 4ground_daemonNov 19, 2019 10:19 PM 5 177 Nov 19, 2019 10:19 PM
Last Post: Wiked™