Friday, 9 August 2013

Making a basic web scrapper in Python with only built in libraries - Python newbie

Making a basic web scrapper in Python with only built in libraries -
Python newbie

I'm quite new to Python, instead of simply reading tutorials I felt that
completing actual project is probably a better way to learn. However, that
means I'd be needing quite some assistance (:
Now to the point.
I'm trying to make a web scrapper without any 3rd party libraries, so that
the process isn't simplified for me, and I know what I am doing. I looked
through several online resources, but all of which have left me confused
about certain things.
The html looks something like this,
<html>
<head>...</head>
<body>
*lots of other <div> tags*
<div class = "want"
style="font-family:verdana;font-size:12px;letter-spacing:normal"">
<form class ="subform">...</form>
<div class = "subdiv1" >...</div>
<div class = "subdiv2" >...</div>
*lots of other <div> tags*
</body>
</html>
I want the scrapper to extract the <div class = "want"...>*content*</div>
and save that into a html file.
I have a very basic idea of how I need to go about this.
import urllib
from urllib import request
#import re
#from html.parser import HTMLParser
response = urllib.request.urlopen("http://website.com")
html = response.read()
#Some how extract that wanted data
f = open('page.html', 'w')
f.write(data)
f.close()
Thank you very much!

No comments:

Post a Comment