This program is simple post and get request implementation. Since Python works almost anywhere this is a handy code to have. ''' This is a comment, If you see this, CGI is not working ''' import sys import urllib2 import urllib '''Pickling is the process converting object into a byte stream, and unpickling is the inverse operation.''' try: import cPickle as … [Read more...] about Post and Get requests in Python
Question is how to read HTML from some URL in Python. Here is the answer: try: r = urllib2.urlopen(url) except: print "Unexpected error, looks that URL isn't available or doesn't exist." sys.exit(0) html = r.read() Thanks … [Read more...] about Read HTML from URL
To extract frequent words from some text we can work with Dict in Python. If you need to disable some words add them to stopword string # prints 40 top keywords for the text def PrintTopKeywords(text): stopwords = 'I we he she a about an and are as at be by com for from how if in is it me more my myself of on or that the this to was what when where who will with you your' … [Read more...] about Extract frequent words from the text in Python
Here is what was needed to make BeautifulSoup project to work. #!/usr/bin/python -tt # -*- coding: utf_8 -*- import sys import os import urllib import urllib2 import re import cgitb cgitb.enable() from BeautifulSoup import BeautifulSoup import scrape from urlparse import urlparse Here are few functions I used for one … [Read more...] about Working with beautifulsoup in Python should be easy
Python is strongly typed language as you may already know. Wikipedia explains that here. Because of that you can check easily object types in Python this way: l=['one','two'] type(l) type 'list' print l.__class__ type 'list' When you need to check you can do it in this pythonic way: l= if type(l).__name__== 'list': print 'Is a list!' else: print 'Not a list' … [Read more...] about How to get python object type?