Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a html_grabber
#1
Here is a bot that will print out and save to a file the complete html of a website. Wow, made my me, at last. I been working on this for over a week now. Dance  It does work very well, made in python2.7.12 om win 7. So let have a look at it.

import urllib
urls = input ('Enter the web site address you want to scrape like this "http://www.google.com" ')


website = urls
filename = input ('Enter the file name you want like this "MyFile.txt "')
htmlfile = urllib.urlopen(website)
htmltext = htmlfile.read()
f = open(filename,"w") #opens file with name of "test.txt"
f.write(htmltext)
f.close()
print htmltext
input("Press the enter key to exit")


   
This is not much, but I hope to be able to give more back to the forum, I have got so much help here.
I want to thank you all for the help
EDIT: I added some more code, you now can name the file you are saving too.
Reply
#2
Well done! It's great you got it working =) I can add a few comments though:

- A bit of a grammar schmazi thing is, "Inter" should be "Enter"
- there's no need for using both, 'website' and 'urls' variables, since you are just assigning same value to another, so you can have just "website = input (.....)"
- for opening files I would recommend using "with open" keywords, you can find plenty about its usage online

Keep up the good work ;)
Reply
#3
The first working script brings a lot of joy. :)
Keep learning
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

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