Welcome, guest | Sign In | My Account | Store | Cart

parse profile information from a myspace.com account.

Python, 36 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: utf-8 -*-

import urllib, urllib2
from re import *


class Profile(object):
    """ parse profile information from a myspace.com account """

    def __init__(self, uid):
        self.uid = uid
        self.profile_url = 'http://profile.myspace.com/'
        self.fake_browser = 'Opera/8.53 (Windows NT 5.1; U; de)'
        self.site = self.__ua()


    def __ua(self):
        opener = urllib2.build_opener()
        opener.addheaders = [('User-agent', self.fake_browser)]
        site = opener.open(self.profile_url+self.uid)
        site = site.read()
        if site:
            return site
        else:
            return False


    def getProfile(self):
        re = compile('<meta name="description" content="MySpace Profile - ([^"]+)" /><meta', I)
        profile_data = re.findall(self.site)
        return profile_data[0].split(', ')


p = Profile(uid="textacrew")
print p.getProfile()