On my administration page I have a list of accounts with various values that I wanna to capture, like id, name, type, etc. On Regex101 its capturing perfectly all the values with "g" and "s" modifiers active. This what I trying to do:
def extract_accounts(src):
list_accounts = []
try:
pattern = re.compile(r'''id=(?P<id>.*?)&serverzone=.\">(?P<name>[a-zA-Z].*?)<\/a>.*?75px;\">(?P<level>.*?)<\/td>.*?75px;.*?75px;\">(?P<type>.*?)<\/td>.*?Open!''', re.X)
print type(pattern)
match = pattern.match(src)
print match, "type=", type(match)
name = match.group("name")
print "name", name
ids = match.group("id")
level = match.group("level")
type = match.group("type")
#list_accounts.append(name, ids, level, type)
#print ("id=", ids, ", name=",name," level=", level, " type=", type)
except Exception as e:
print (e)
But somehow I get this:
<type '_sre.SRE_Pattern'>
None type= <type 'NoneType'>
'NoneType' object has no attribute 'group'
I don't have a clue what I'm doing wrong. Basically what I want is to put in a list = [(name1, id1, level1, type), (name2, id2, level1, type) ..... and so on the things that I grab from each line Thanks in advance for any help.
re.findall()because of a special character in the string, in your case its the • next to Evolution. python can't handle that