Jan 5, 2017 05:46 PM
(This post was last modified: Jan 6, 2017 07:39 PM by Xogg.)
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
Jan 5, 2017 05:57 PM
(This post was last modified: Jan 5, 2017 05:58 PM by Dialog.)
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.
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)
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.
DO NOT DEAL WITH THIS MEMBER
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 7, 2017 12:47 AM
(This post was last modified: Jan 7, 2017 12:48 AM by Xogg.)
(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
(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.
(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.
(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
(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.
(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.
DO NOT DEAL WITH THIS MEMBER
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
DO NOT DEAL WITH THIS MEMBER
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 :)
|