Python Forum
this would be silly if it as not driving mr crazy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
this would be silly if it as not driving mr crazy
#11
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.
Reply
#12
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
Reply
#13
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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#14
(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
Reply
#15
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?
Reply
#16
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
Reply
#17
thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A crazy project involving webpage interaction apsaditya 7 4,998 May-20-2018, 05:39 AM
Last Post: apsaditya

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020