I'm working on a problem that I can't resolve since this morning. I tried a lot of thing but it never works.
I explain you my problem. I have a list in python and in this list I have a dictionary , like this :
"links": [{"url": "http://catherineingram.com/biography.html", "type": {"key": "/type/link"}, "title": "Biography"}, {"url": "http://www.youtube.com/watch?v=4lJK9cfXP3c", "type": {"key": "/type/link"}, "title": "Interview on Consciousness TV"}, {"url": "http://www.huffingtonpost.com/catherine-ingram/", "type": {"key": "/type/link"}, "title": "Blog on Huffington Post"}]
And my goal is to recover the 3 elements of URL and put it in my database and I try too to recover the 3 element title and put it in my database
I tried it
for record in csv.DictReader(open(INPUT_FILE, 'r'), fieldnames=COLUMNS, delimiter='\t'):
j = json.loads(record['json'])
if 'links' in j:
for n in j['links']:
lien.append(n)
print(lien)
dico = {"url": lien[(0)]}
print(dico)
else:
links= ''
Here input file here ties in the links that I give you above.
So I would like to know How can I got only "url" and "title" from my links
The results about what I did( my code that I show you ) is :
[{'url': 'http://catherineingram.com/biography.html', 'type': {'key': '/type/link'}, 'title': 'Biography'}, {'url': 'http://www.youtube.com/watch?v=4lJK9cfXP3c', 'type': {'key': '/type/link'}, 'title': 'Interview on Consciousness TV'}, {'url': 'http://www.huffingtonpost.com/catherine-ingram/', 'type': {'key': '/type/link'}, 'title': 'Blog on Huffington Post'}]
{'url': {'url': 'http://catherineingram.com/biography.html', 'type': {'key': '/type/link'}, 'title': 'Biography'}}
And I would like to have only these element :
'url': 'http://catherineingram.com/biography.html'
'title': 'Biography'
'url': 'http://www.youtube.com/watch?v=4lJK9cfXP3c'
'title': 'Interview on Consciousness TV'
'url': 'http://www.huffingtonpost.com/catherine-ingram/'
'title': 'Blog on Huffington Post'