Karthik Bodapati Karthik Bodapati - 1 year ago 68
Python Question

How to extract a part of data, that we get from website using url.open()

I wrote a Program that connects to this website

http://mbox.dr-chuck.net/sakai.devel/1/2

I need to parse it and get email in that website

url = http://mbox.dr-chuck.net/sakai.devel/1/2
data = urllib.urlopen(url).read()
for line in data:
templine = line.strip()
print templine


but it prints individual letters instead of words
like when i try to print a particular line from it

F
r
o
m

n
e
w
s


how to fix this please help me
what to do,I need my program to print as lines


  • sorry about my language, this is my first question to post


Answer Source
url = 'http://mbox.dr-chuck.net/sakai.devel/1/2'
data = urllib.urlopen(url).readlines()
for line in data:
    if line.startswith('From'):
        print (line)

out:

From [email protected] Tue Mar 04 03:33:20 2003

From: "Glenn R. Golden" <[email protected]>

use readlines() to get each line in the file

use startswith() to get line which starts with From

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download