xml - Getting youtube data with python -
how url views in youtube? here link using, "http://gdata.youtube.com/feeds/api/videos?q=gangnam%20style"
it returns xml data, how elements of this? module use return gdata link go viewed video? appreciated thank you. problem not know how elements why i'm asking , thank ahead of time.
edit: thank answerd after hour or on google found way appreicate of suggestions, in few hours when can answer own question i'll post it
use lxml
.
for example, following code prints titles, view counts:
import lxml.etree tree = lxml.etree.parse('http://gdata.youtube.com/feeds/api/videos?q=gangnam%20style') root = tree.getroot() nsmap = root.nsmap nsmap['xmlns'] = nsmap.pop(none) entry in root.findall('.//xmlns:entry', namespaces=nsmap): title = entry.find('xmlns:title', namespaces=nsmap).text view_count = entry.find('yt:statistics', namespaces=nsmap).get('viewcount') print(u'{} {}'.format(title, view_count))
Comments
Post a Comment