Get Specific attribute value from python library sholarly.py output
Question:
i am new to python and Django. I am trying the python library "scholarly.py" to gather article url (to pdf or to eprint) on a django webpage.
Here’s what the sample input looks like:
>>> search_query = scholarly.search_pubs('Perception of physical stability and center of mass of 3D objects')
>>> print(next(search_query))
Here’s what the output looks like:
{'bib': {'abstract': 'Humans can judge from vision alone whether an object is '
'physically stable or not. Such judgments allow observers '
'to predict the physical behavior of objects, and hence '
'to guide their motor actions. We investigated the visual '
'estimation of physical stability of 3-D objects (shown '
'in stereoscopically viewed rendered scenes) and how it '
'relates to visual estimates of their center of mass '
'(COM). In Experiment 1, observers viewed an object near '
'the edge of a table and adjusted its tilt to the '
'perceived critical angle, ie, the tilt angle at which '
'the object',
'author': ['SA Cholewiak', 'RW Fleming', 'M Singh'],
'cites': '23',
'eprint': 'https://jov.arvojournals.org/article.aspx?articleID=2213254',
'gsrank': '1',
'title': 'Perception of physical stability and center of mass of 3-D '
'objects',
'url': 'https://jov.arvojournals.org/article.aspx?articleID=2213254',
'venue': 'Journal of vision',
'year': '2015'},
'citations_link': '/scholar?cites=15736880631888070187&as_sdt=5,33&sciodt=0,33&hl=en',
'filled': False,
'source': 'scholar',
'url_add_sclib': '/citations?hl=en&xsrf=&continue=/scholar%3Fq%3DPerception%2Bof%2Bphysical%2Bstability%2Band%2Bcenter%2Bof%2Bmass%2Bof%2B3D%2Bobjects%26hl%3Den%26as_sdt%3D0,33&citilm=1&json=&update_op=library_add&info=K8ZpoI6hZNoJ&ei=ewEtX7_JOIvrmQHcvJqoDA',
'url_scholarbib': '/scholar?q=info:K8ZpoI6hZNoJ:scholar.google.com/&output=cite&scirp=0&hl=en'}
As you can see this output looks like JSON but it is not JSON.
What do I have to do if I want to get only "url" value from that output.
Thank you.
Answers:
The object you get returned from the iterator is most likely a Python dictionary and you can access it as such:
>>> next(search_query).bib['url']
'https://jov.arvojournals.org/article.aspx?articleID=2213254'
Looking a little bit at the limited documentation of that script you might have to play with the .fill
function aswell.
i am new to python and Django. I am trying the python library "scholarly.py" to gather article url (to pdf or to eprint) on a django webpage.
Here’s what the sample input looks like:
>>> search_query = scholarly.search_pubs('Perception of physical stability and center of mass of 3D objects')
>>> print(next(search_query))
Here’s what the output looks like:
{'bib': {'abstract': 'Humans can judge from vision alone whether an object is '
'physically stable or not. Such judgments allow observers '
'to predict the physical behavior of objects, and hence '
'to guide their motor actions. We investigated the visual '
'estimation of physical stability of 3-D objects (shown '
'in stereoscopically viewed rendered scenes) and how it '
'relates to visual estimates of their center of mass '
'(COM). In Experiment 1, observers viewed an object near '
'the edge of a table and adjusted its tilt to the '
'perceived critical angle, ie, the tilt angle at which '
'the object',
'author': ['SA Cholewiak', 'RW Fleming', 'M Singh'],
'cites': '23',
'eprint': 'https://jov.arvojournals.org/article.aspx?articleID=2213254',
'gsrank': '1',
'title': 'Perception of physical stability and center of mass of 3-D '
'objects',
'url': 'https://jov.arvojournals.org/article.aspx?articleID=2213254',
'venue': 'Journal of vision',
'year': '2015'},
'citations_link': '/scholar?cites=15736880631888070187&as_sdt=5,33&sciodt=0,33&hl=en',
'filled': False,
'source': 'scholar',
'url_add_sclib': '/citations?hl=en&xsrf=&continue=/scholar%3Fq%3DPerception%2Bof%2Bphysical%2Bstability%2Band%2Bcenter%2Bof%2Bmass%2Bof%2B3D%2Bobjects%26hl%3Den%26as_sdt%3D0,33&citilm=1&json=&update_op=library_add&info=K8ZpoI6hZNoJ&ei=ewEtX7_JOIvrmQHcvJqoDA',
'url_scholarbib': '/scholar?q=info:K8ZpoI6hZNoJ:scholar.google.com/&output=cite&scirp=0&hl=en'}
As you can see this output looks like JSON but it is not JSON.
What do I have to do if I want to get only "url" value from that output.
Thank you.
The object you get returned from the iterator is most likely a Python dictionary and you can access it as such:
>>> next(search_query).bib['url']
'https://jov.arvojournals.org/article.aspx?articleID=2213254'
Looking a little bit at the limited documentation of that script you might have to play with the .fill
function aswell.