<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>Hi<BR>
&nbsp;<BR>
i was expanding my program to write urls parsed from a html page and write them to a file so i chose <A href="http://www.icq.com">www.icq.com</A> to extract the urls from.<BR>
&nbsp;<BR>
when i wrote these out to a file and then read the file back I noticed a list of urls then some blank lines then some more urls then some blank lines, does this mean that one of the functions called has for some reason added some whitespace into some of the list items so that i wrote them out to disk?<BR>
&nbsp;<BR>
I also noticed that there are duplicate hosts/urls that have been written to the file.<BR>
&nbsp;<BR>
So my two questions are;<BR>
1. how and where do I tackle removing the whitespace from being written out to disk?<BR>
&nbsp;<BR>
2. how do i tackle checking for duplicate entries in a list before writing them out to disk?<BR>
&nbsp;<BR>
My code is below <BR>
from BeautifulSoup import BeautifulSoup<BR>import urllib2<BR>import urlparse<BR>
file = urllib2.urlopen("<A href="http://www.icq.com">http://www.icq.com</A>")<BR>
soup = BeautifulSoup(''.join(file))<BR>alist = soup.findAll('a')<BR>
output = open("fqdns.txt","w")<BR>
for a in alist:<BR>&nbsp;&nbsp;&nbsp; href = a['href']<BR>&nbsp;&nbsp;&nbsp; output.write(urlparse.urlparse(href)[1] + "\n")<BR>
output.close()<BR>
input = open("fqdns.txt","r")<BR>
for j in input:<BR>&nbsp;&nbsp;&nbsp; print j,<BR>
input.close()<BR><BR>
the chopped output is here <BR>
&nbsp;<BR>
chat.icq.com<BR>chat.icq.com<BR>chat.icq.com<BR>chat.icq.com<BR>chat.icq.com<BR>
&nbsp;<BR>
&nbsp;<BR>
labs.icq.com<BR>download.icq.com<BR>greetings.icq.com<BR>greetings.icq.com<BR>greetings.icq.com<BR>games.icq.com<BR>games.icq.com<BR><br /><hr />Get free emoticon packs and customisation from Windows Live.  <a href='http://www.pimpmylive.co.uk' target='_new'>Pimp My Live!</a></body>
</html>