Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python库sholarly.py输出中获取特定属性值_Python_Python 3.x - Fatal编程技术网

从python库sholarly.py输出中获取特定属性值

从python库sholarly.py输出中获取特定属性值,python,python-3.x,Python,Python 3.x,我不熟悉python和Django。我正在尝试使用python库“”在django网页上收集文章url(到pdf或到eprint) 下面是示例输入的样子: >>> search_query = scholarly.search_pubs('Perception of physical stability and center of mass of 3D objects') >>> print(next(search_query)) {'bib': {'abs

我不熟悉python和Django。我正在尝试使用python库“”在django网页上收集文章url(到pdf或到eprint)

下面是示例输入的样子:

>>> search_query = scholarly.search_pubs('Perception of physical stability and center of mass of 3D objects')
>>> print(next(search_query))
{'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'}
以下是输出结果:

>>> search_query = scholarly.search_pubs('Perception of physical stability and center of mass of 3D objects')
>>> print(next(search_query))
{'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'}
正如您所看到的,这个输出看起来像JSON,但它不是JSON。 如果我只想从输出中获取“url”值,我该怎么办


谢谢。

从迭代器返回的对象很可能是Python字典,您可以这样访问它:

>>> next(search_query)['bib']['url']
'https://jov.arvojournals.org/article.aspx?articleID=2213254'
看看这个脚本的局限性,您可能还需要使用
.fill
函数。

谢谢

>>> next(search_query)['bib']['url']
这实际上不起作用,但这让我找到了正确的答案。即:

>>> next(search_query).bib['url']
再次感谢:)