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

Python 

WebRequests in python?

So i know VB.net and to download a site as a string you do something like this


i would like to know how to do this in Python, if you need any more additional info please ask.

Thanks 🤝

PS: Im using python 2.7
[Image: F2G97kn.png]
Equivalent of your code using urllib2:
Code
import urllib2

results = urllib2.urlopen('https://www.youtube.com').read()
print results
Except don't use urllib2. Use requests. It's an incredibly common, supported, and featurefull extension that can be downloaded with pip.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
I'd definetly recommend using requests. It's really easy to use and has a good documentation. http://docs.python-requests.org/en/master/

The equivalent to your code would be
Code
import requests
r = requests.get("https://www.youtube.com")
print(r.text)
Veni, Vidi, Vici


Honestly there are a myriad of libraries on requests;

sockets
urllib
urllib2
requests
(forgot the rest)

Sockets is the Assembly of the Urllib which is C to the Python-level requests.

(Sockets = hardest, Urllib = intermediate-ish, Requests = ez pz)
Contact for professional programming services.
unazed#5906
Bump i still need help. None of the results seemed to work for me.
[Image: F2G97kn.png]
PHP Code

<?php 
import requests
r 
= requests.get("https://www.youtube.com")
print(
r.text) 
If this doesn't work then either we misunderstand what you're trying to do or there's a problem with your python.

Please post the error you're getting here.
(Jan 6, 2017 11:02 PM)xthanos Wrote:  
PHP Code

<?php 
import requests
r 
= requests.get("https://www.youtube.com")
print(
r.text) 
If this doesn't work then either we misunderstand what you're trying to do or there's a problem with your python.

Please post the error you're getting here.




PHP Code

<?php 
Traceback 
(most recent call last):
  
File "C:/Users/OWNER/Documents/Python 2.7/Projects/IP Locator/IP Locator.py", line 1, in <module>
    
import requests
ImportError
: No module named requests 
[Image: F2G97kn.png]
(Jan 7, 2017 12:47 AM)Xogg Wrote:  
PHP Code

<?php 
Traceback 
(most recent call last):
  
File "C:/Users/OWNER/Documents/Python 2.7/Projects/IP Locator/IP Locator.py", line 1, in <module>
    
import requests
ImportError
: No module named requests 
You need to install pip and then use that to install the requests library.
[Image: npafFhp.gif]
(Jan 7, 2017 12:49 AM)Retribute Wrote:  You need to install pip and then use that to install the requests library.

Can you point me in the correct direction, im using a windows machine if that helps.
[Image: F2G97kn.png]
(Jan 7, 2017 12:56 AM)Xogg Wrote:  Can you point me in the correct direction, im using a windows machine if that helps.
The installation docs:
https://pip.pypa.io/en/stable/installing
[Image: npafFhp.gif]
(Jan 7, 2017 12:56 AM)Xogg Wrote:  Can you point me in the correct direction, im using a windows machine if that helps.

If you are using pip, just type "pip install requests" in your console, this will install the requests library.
Veni, Vidi, Vici


(Jan 7, 2017 12:56 AM)Xogg Wrote:  Can you point me in the correct direction, im using a windows machine if that helps.

You should have it, if not read this, if you do have it just type "pip install requests" in the command line.
PHP Code

<?php 
import urllib

string 
= urllib.urlopen("https://www.youtube.com").read()

import mechanize

op 
= mechanize.Browser()
string = op.open("https://www.youtube.com").read()


import requests

string 
= requests.get("https://www.youtube.com").text 
You don't have pip installed. Ok so firstly you need python in your enviroment variable: https://www.youtube.com/watch?v=hKvJL6AlTI8
This is extrememly useful ^^

After you've done all that, you may need to restart pc. Type into CMD :

PHP Code

<?php 
python 
-m pip install requests 
Then run the code. That should fix everything :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 631 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C#] by NinjaDec 24, 2017 02:22 PM 15 568 Dec 24, 2017 02:22 PM
Last Post: Ninja
[.NET] by Cody8295Dec 8, 2016 12:09 PM 17 976 Dec 8, 2016 12:09 PM
Last Post: elmagek