I want to send a REST request to the Flickr API. The response looks like this (XML):
This XML file does not appear to have any style information associated with it. The
document tree is shown below.
<rsp stat="ok">
<photos page="1" pages="974001" perpage="250" total="243500161">
<photo id="123" owner="1234" secret="123" server="1" farm="4"
title="DSC01316" ispublic="1" isfriend="0" isfamily="0" views="0" tags=""
latitude="47.825188" longitude="11.300722" accuracy="16" context="0"
place_id="XT" woeid="123" geo_is_family="0" geo_is_friend="0"
geo_is_contact="0" geo_is_public="1">
<description/>
</photo>
<photo id="123" owner="123" secret="123" server="1" farm="3"
title="DSC01351" ispublic="1" isfriend="0" isfamily="0" views="0" tags=""
latitude="47.825263" longitude="11.300891" accuracy="16" context="0"
place_id="XT" woeid="123" geo_is_family="0" geo_is_friend="0"
geo_is_contact="0" geo_is_public="1">
<description/>
</photo>
and so forth...
What I want python to do is parsing the website for the words photo ID, Owner, Title etc. and extract the information and save it into a mysql database (set that already up with phpadmin).
For better understanding: I have this table where the first row is my classification and the second row is the extracted data from the example.
Photo ID Owner Secret Server Farm Title ispublic isfriend isfamily ....
123 1234 123 1 4 DSC01316 1 0 0
I started off with that to extract the information. It does not work though...
import xml.etree.ElementTree as ET
import requests
url="https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=5...b&per_page=250&accuracy=1&has_geo=1&extras=geo,tags,views,description%22"
page=requests.get(url)
data = page.text
root = ET.fromstring(data)
for x in root.Element.get('photo'):
test = x.get('Photo ID', 'Owner', 'Secret' , 'Server' , 'Farm' , 'Title' , 'ispublic' , 'isfriend' , 'isfamily')
print (test)
#does not work. it says: AttributeError: 'Element' object has no attribute 'Element'
Any ideas? I am just looking for a hint, I want to write it myself! Note that I am relatively new to python and a link to a documentation site wont work for me. i have too less knowledge for that. I will need a little further explanation. Thanks!