I recommend using BeautifulSoup
where you can for something like this because it's just so easy to use.
from bs4 import BeautifulSoup as BS
# given your html as the variable 'html'
soup = BS(html, "xml")
pages = soup.find_all('page')
for page in pages:
if page.ns.text == '0':
print page.title.text
As far as I can tell here, no need to use int
to convert your <ns>
tag to an integer to compare against == 0
. Comparing against the string '0'
works just as well--even easier, in this case, since you wouldn't have to deal with conversion at all.