Python print regex in json string -



Python print regex in json string -

so, i'm using little python script seek print out every occurrence of website 'northwest.hall.' wildcard() number, in big json string pulled url.

i have far: import urllib, json, re

url = 'http://graphite.website.com/render/?target=stats.web.northwest.hall.*&format=json' response = urllib.urlopen(url) info = json.loads(response.read()) code = re.findall('northwest', data) print code

this should homecoming list of 30 regexpressions of northwest.hall.number in json string beingness parsed, next error instead:

traceback (most recent phone call last): file "/users/arin/desktop/scripts/code_parser2.py", line 7, in <module> code = re.findall('community', data) file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/re.py", line 177, in findall homecoming _compile(pattern, flags).findall(string) typeerror: expected string or buffer

new python (sure can tell). in advance.

use

data = response.read()

to json string server.

using

data = json.loads(response.read())

you alter string python dictionary.

edit:

import re info = """ stats.web.northwest.hall.01 stats.web.northwest.hall.223 stats.web.northwest.hall.31 stats.web.northwest.hall.4 """ print re.findall(r'stats.web.northwest.hall.(\d+)', data) ['01', '223', '31', '4']

python regex json

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -