I'm newbie to python. Here is my code working on python 2.7.5
import urllib2
import sys
url ="mydomain.com"
usock = urllib2.urlopen(url)
data = usock.read()
usock.close()
print data
Getting HTML markup like that and it works.
What I want to do is, to get value from inside <font class="big"></font>
tag. for ex. I need data value from this example:
<font class="big">Data</font>
How to do it?
You can use a HTML parser module such as BeautifulSoup
:
from bs4 import BeautifulSoup as BS
url ="mydomain.com"
usock = urllib2.urlopen(url)
data = usock.read()
usock.close()
soup = BS(data)
print soup.find('font', {'class':'big'}).text
This finds a tag <font>
with a class="big"
. It then prints its content.
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