繁体   English   中英

如图所示,我如何从长字典中获取特定数据

[英]How would I get specific data from a long dictionary as shown

所以基本上我有一个名为“结果”的变量,它存储用户输入的任何种子信息。 我将如何 go 关于获取特定数据,例如链接、大小、名称等。输入“哈利波特”这个词的结果如下,我将如何 go 呢?

{
  'items': [
      {'name': 'Harry Potter And The Deathly Hallows Part 2 (2011) 720p - YIFY',
       'torrentId': '258188',
       'link': 'https://www.1337xx.to/torrent/258188/Harry-Potter-And-The-Deathly-Hallows-Part-2-2011-720p-YIFY/',
       'seeders': '1009',
       'leechers': '91',
       'size': '1.0 GB',
       'time': "Oct. 26th '11",
       'uploader': 'YIFY',
       'uploaderLink': 'https://www.1337xx.to/YIFY/'},
      {'name': 'Harry Potter and the Order of the Phoenix 2007 1080p BrRip x264 YIFY',
       'torrentId': '1335348',
       'link': 'https://www.1337xx.to/torrent/1335348/Harry-Potter-and-the-Order-of-the-Phoenix-2007-1080p-BrRip-x264-YIFY/',
       'seeders': '767',
       'leechers': '103',
       'size': '1.9 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Sorcerers Stone 2001 1080p BrRip x264 YIFY FIRST TRY',
       'torrentId': '1335352',
       'link': 'https://www.1337xx.to/torrent/1335352/Harry-Potter-and-the-Sorcerers-Stone-2001-1080p-BrRip-x264-YIFY-FIRST-TRY/',
       'seeders': '741',
       'leechers': '149',
       'size': '1.2 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Goblet of Fire 2005 1080p BrRip x264 YIFY',
       'torrentId': '1339302',
       'link': 'https://www.1337xx.to/torrent/1339302/Harry-Potter-and-the-Goblet-of-Fire-2005-1080p-BrRip-x264-YIFY/',
       'seeders': '721',
       'leechers': '151',
       'size': '2.1 GB',
       'time': "Oct. 31st '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Chamber of Secrets 2002 720p BrRip x264 YIFY',
       'torrentId': '1339492',
       'link': 'https://www.1337xx.to/torrent/1339492/Harry-Potter-and-the-Chamber-of-Secrets-2002-720p-BrRip-x264-YIFY/',
       'seeders': '714',
       'leechers': '102',
       'size': '599.8 MB',
       'time': "Oct. 31st '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Deathly Hallows: Part 1 2010 720p YIFY',
       'torrentId': '1335299',
       'link': 'https://www.1337xx.to/torrent/1335299/Harry-Potter-and-the-Deathly-Hallows-Part-1-2010-720p-YIFY/',
       'seeders': '712',
       'leechers': '81',
       'size': '998.6 MB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Half Blood Prince 2009 1080p BrRip x264 YIFY',
       'torrentId': '1335343',
       'link': 'https://www.1337xx.to/torrent/1335343/Harry-Potter-and-the-Half-Blood-Prince-2009-1080p-BrRip-x264-YIFY/',
       'seeders': '686',
       'leechers': '100',
       'size': '2.0 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Prisoner of Azkaban 2004 720p BrRip x264 YIFY',
       'torrentId': '1338321',
       'link': 'https://www.1337xx.to/torrent/1338321/Harry-Potter-and-the-Prisoner-of-Azkaban-2004-720p-BrRip-x264-YIFY/',
       'seeders': '661',
       'leechers': '61',
       'size': '549.4 MB',
       'time': "Oct. 30th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Philosophers Stone 2001 720p YIFY',
       'torrentId': '1337916',
       'link': 'https://www.1337xx.to/torrent/1337916/Harry-Potter-and-the-Philosophers-Stone-2001-720p-YIFY/',
       'seeders': '598',
       'leechers': '77',
       'size': '549.3 MB',
       'time': "Oct. 30th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Half Blood Prince 2009 720p BrRip x264 YIFY',
       'torrentId': '1337180',
       'link': 'https://www.1337xx.to/torrent/1337180/Harry-Potter-and-the-Half-Blood-Prince-2009-720p-BrRip-x264-YIFY/',
       'seeders': '455',
       'leechers': '54',
       'size': '651.2 MB',
       'time': "Oct. 29th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Goblet of Fire 2005 720p BrRip x264 YIFY',
       'torrentId': '1340819',
       'link': 'https://www.1337xx.to/torrent/1340819/Harry-Potter-and-the-Goblet-of-Fire-2005-720p-BrRip-x264-YIFY/',
       'seeders': '453',
       'leechers': '59',
       'size': '599.0 MB',
       'time': "Nov. 1st '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Chamber of Secrets 2002 1080p BrRip x264 YIFY',
       'torrentId': '1335344',
       'link': 'https://www.1337xx.to/torrent/1335344/Harry-Potter-and-the-Chamber-of-Secrets-2002-1080p-BrRip-x264-YIFY/',
       'seeders': '436',
       'leechers': '84',
       'size': '2.1 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Deathly Weapons (2020) 1080p WEB-DL AV1 Opus',
       'torrentId': '4594380',
       'link': 'https://www.1337xx.to/torrent/4594380/Harry-Potter-and-the-Deathly-Weapons-2020-1080p-WEB-DL-AV1-Opus/',
       'seeders': '427',
       'leechers': '53',
       'size': '1.2 GB',
       'time': "Aug. 15th '20",
       'uploader': 'jAV1er',
       'uploaderLink': 'https://www.1337xx.to/jAV1er/'},
      {'name': 'Harry Potter and the Order of the Phoenix 2007 720p YIFY',
       'torrentId': '1340862',
       'link': 'https://www.1337xx.to/torrent/1340862/Harry-Potter-and-the-Order-of-the-Phoenix-2007-720p-YIFY/',
       'seeders': '396',
       'leechers': '52',
       'size': '549.9 MB',
       'time': "Nov. 1st '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter And The Deathly Hallows Part 2 (2011) 1080p - YIFY',
       'torrentId': '258988',
       'link': 'https://www.1337xx.to/torrent/258988/Harry-Potter-And-The-Deathly-Hallows-Part-2-2011-1080p-YIFY/',
       'seeders': '357',
       'leechers': '65',
       'size': '1.7 GB',
       'time': "Oct. 28th '11",
       'uploader': 'YIFY',
       'uploaderLink': 'https://www.1337xx.to/YIFY/'},
      {'name': 'Harry.Potter.And.The.Deathly.Hallows.Part.2.2011.FRENCH.BRRip.XviD-LKT',
       'torrentId': '370236',
       'link': 'https://www.1337xx.to/torrent/370236/Harry-Potter-And-The-Deathly-Hallows-Part-2-2011-FRENCH-BRRip-XviD-LKT/',
       'seeders': '353',
       'leechers': '17',
       'size': '1.4 GB',
       'time': "Jul. 19th '12",
       'uploader': 'maximersk',
       'uploaderLink': 'https://www.1337xx.to/maximersk/'},
      {'name': 'Harry.Potter.And.The.Deathly.Hallows.Part.1.2010.FRENCH.BRRip.XviD-LKT',
       'torrentId': '370238',
       'link': 'https://www.1337xx.to/torrent/370238/Harry-Potter-And-The-Deathly-Hallows-Part-1-2010-FRENCH-BRRip-XviD-LKT/',
       'seeders': '301',
       'leechers': '6',
       'size': '695.3 MB',
       'time': "Jul. 19th '12",
       'uploader': 'maximersk',
       'uploaderLink': 'https://www.1337xx.to/maximersk/'},
      {'name': 'Harry Potter and the Prisoner of Azkaban 2004 1080p BrRip x264 YIFY',
       'torrentId': '1335347',
       'link': 'https://www.1337xx.to/torrent/1335347/Harry-Potter-and-the-Prisoner-of-Azkaban-2004-1080p-BrRip-x264-YIFY/',
       'seeders': '299',
       'leechers': '67',
       'size': '1.9 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'},
      {'name': 'Harry Potter and the Prisoner of Azkaban (2004) 1080p.BRrip.scOrp.sujaidr (pimprg)',
       'torrentId': '631062',
       'link': 'https://www.1337xx.to/torrent/631062/Harry-Potter-and-the-Prisoner-of-Azkaban-2004-1080p-BRrip-scOrp-sujaidr-pimprg/',
       'seeders': '221',
       'leechers': '16',
       'size': '1.7 GB',
       'time': "Sep. 19th '13",
       'uploader': 'sujaidr',
       'uploaderLink': 'https://www.1337xx.to/sujaidr/'},
      {'name': 'Harry Potter and the Deathly Hallows Part 1 2010 1080p BrRip x264 YIFY',
       'torrentId': '1335533',
       'link': 'https://www.1337xx.to/torrent/1335533/Harry-Potter-and-the-Deathly-Hallows-Part-1-2010-1080p-BrRip-x264-YIFY/',
       'seeders': '208',
       'leechers': '49',
       'size': '2.0 GB',
       'time': "Oct. 28th '15",
       'uploader': 'CharlieJade',
       'uploaderLink': 'https://www.1337xx.to/CharlieJade/'}
    ],
  'currentPage': 1,
  'itemCount': 20,
  'pageCount': 50
}

您可以使用键(例如链接、名称、大小)访问字典值。 在您的示例中:

link = results['items'][0]['link']
name = results['items'][0]['name']
size = results['items'][0]['size']

print("Content of link: " + link)
print("Content of name: " + name)
print("Content of size: " + size)

在处理如此复杂的字典之前,我建议您阅读字典教程。 有很多很好的教程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM