import urllib2
from BeautifulSoup import *
resp = urllib2.urlopen("file:///D:/sample.html")
rawhtml = resp.read()
resp.close()
print rawhtml
I am using this code to get text from a html document, but it also gives me html code. What should i do to fetch only text from the html document?
Note that your example makes no use of Beautifulsoup. See the doc, and follow examples.
The following example, taken from the link above, searches the soup for <td> elements.
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen("http://www.icc-ccs.org/prc/piracyreport.php")
soup = BeautifulSoup(page)
for incident in soup('td', width="90%"):
where, linebreak, what = incident.contents[:3]
print where.strip()
print what.strip()
print
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With