Python Forum
this would be silly if it as not driving mr crazy - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: this would be silly if it as not driving mr crazy (/thread-666.html)

Pages: 1 2


RE: this would be silly if it as not driving mr crazy - Yoriz - Oct-27-2016

When you have some code to show paste it in code tags instead of showing a picture.
The way you are running the code you need to use print to see output.


RE: this would be silly if it as not driving mr crazy - Blue Dog - Oct-27-2016

Here you go, if I can get it to work right.

import requests
 
htmlfile = requests.get('http://www.google.com')
htmltext = htmlfile.text
This is what I get when I use scrip tags


RE: this would be silly if it as not driving mr crazy - sparkz_alot - Oct-27-2016

what are you using to write your code?  You have several options when posting your code:
1) If it's something like PyCharm, use the "Copy as Plain Text" under the Edit menu, paste between code tags
2) Use [Control] + [Shift] + [v] to paste
3) Copy code to non-formatting text editor (i.e.: Notepad), then re-copy and paste between code tags
4) I think you can use the "Remove Formatting" button on the menu bar (never used that one, so I don't know if that works)

Check the Help docs, when ever you're in doubt about something  Smile


RE: this would be silly if it as not driving mr crazy - snippsat - Oct-27-2016

(Oct-27-2016, 06:37 PM)Blue Dog Wrote: This is what I get when I use scrip tags
You are stuggling with very basic stuff Undecided

When i test my code i eailer in post i use shell(interactive interpreter).
Then i do not need to use print.

Here as a script.
import requests
 
htmlfile = requests.get('http://www.google.com')
htmltext = htmlfile.text
print(htmltext)
If run in shell(interactive interpreter)
>>> htmltext # Enter



RE: this would be silly if it as not driving mr crazy - Blue Dog - Oct-27-2016

That is what I am doing, 3.5 I use vs express, but 2.7.5 I just us what comes up when i click on it.

Do you get the html from google when you run it?


RE: this would be silly if it as not driving mr crazy - snippsat - Oct-27-2016

Quote:Do you get the html from google when you run it?
Yes,here is the explanation of code that i post before.
import requests
 
htmlfile = requests.get('http://www.google.com')
htmltext = htmlfile.text
Now i run in shell(interactive interpreter).
You use print() if you want this in a script.
# Show that everything went okay
>>> htmlfile.status_code
200

# The html encoding that site use
>>> htmlfile.encoding
'ISO-8859-1'

# Header carry information about the client browser, the requested page, the server and more.
>>> htmlfile.headers
{'content-length': '4622', 'x-xss-protection': '1; mode=block', 'content-encoding': 'gzip',...ect

# Here you get the html source code,as eg can be send to BeautifulSoup for parsing
>>> htmltext



RE: this would be silly if it as not driving mr crazy - Blue Dog - Oct-27-2016

thank you