Take the 2-minute tour ×  Is there a more
succinct/correct/pythonic way to do the following:  url = ""
re_token =
re.compile("<[^>]*authenticity_token[^>]*value=\"([^\"]*)") for
line in urllib2.urlopen(url):     if re_token.match(line):
token = re_token.findall(line)[0]  I want to get the value of
the input tag named "authenticity_token" from an HTML page:
<input name="authenticity_token" type="hidden"
value="WTumSWohmrxcoiDtgpPRcxUMh/D9m7O7T6HOhWH+Yw4=" />
share|improve this question The proper way to do this is to use
an HTML parser like BeautifulSoup:
crummy.com/software/BeautifulSoup. See here for the reason:
stackoverflow.com/questions/701166/… –  Ayman Hourieh Nov 8 '09
at 23:10 regexes shouldn't be used with html/XML -- too many
ways for things to break. Look at the BeautiflSoup or one of the
html parser modules. –  Brian C. Lane Nov 8 '09 at 23:11 You
need to use a parser like BeautifulSoup. What if you use a regex
and a malicious user works out a way to put some text that
matches the regex s