Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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 解析json文件并将字符串添加到URL_Python - Fatal编程技术网

Python 解析json文件并将字符串添加到URL

Python 解析json文件并将字符串添加到URL,python,Python,如何解析json输出仅从数据获取列表,然后将输出添加到例如google.com/confidetial和列表中的其他字符串中。 所以我的json输出我将它命名为“文本” 我想做的是只在数据下获取列表。到目前为止,我得到的脚本提供了整个json输出 json.loads(text) print text output = urllib.urlopen("http://google.com" % text) print output.geturl() print output.read() 将在

如何解析json输出仅从数据获取列表,然后将输出添加到例如google.com/confidetial和列表中的其他字符串中。 所以我的json输出我将它命名为“文本”

我想做的是只在数据下获取列表。到目前为止,我得到的脚本提供了整个json输出

json.loads(text)
print text 
output = urllib.urlopen("http://google.com" % text)
print output.geturl()
print output.read()
将在JSON的
数据
部分打印列表

如果您想在
google.com
之后打开每个链接,可以尝试以下方法:

def processlinks(text):
    output = urllib.urlopen('http://google.com/' % text)
    print output.geturl()
    print output.read()

map(processlinks, jsonobj['data'])
将在JSON的
数据
部分打印列表

如果您想在
google.com
之后打开每个链接,可以尝试以下方法:

def processlinks(text):
    output = urllib.urlopen('http://google.com/' % text)
    print output.geturl()
    print output.read()

map(processlinks, jsonobj['data'])
使用
json.dumps
将从
json.loads
获取的python数据结构转换回常规json文本

因此,您可以在以前使用
text
的任何地方使用
json\u text
,并且在您的情况下,它应该只有选中的键:
“data”

使用
json.dumps
将从
json.loads
获取的python数据结构转换回常规json文本


因此,您可以在之前使用
text
的任何地方使用
json\u text
,并且它应该只有选中的键,在您的情况下:
“data”

可能类似这样的东西,其中
result
是您的json数据:

from itertools import product

base_domains = ['http://www.google.com', 'http://www.example.com']
result = {"success":True,"code":200,"data":["Confidential","L1","Secret","Secret123","foobar","maret1","maret2","posted","rontest"],"errs":[],"debugs":[]}
for path in product(base_domains, result['data']):
    print '/'.join(path) # do whatever

http://www.google.com/Confidential
http://www.google.com/L1
http://www.google.com/Secret
http://www.google.com/Secret123
http://www.google.com/foobar
http://www.google.com/maret1
http://www.google.com/maret2
http://www.google.com/posted
http://www.google.com/rontest
http://www.example.com/Confidential
http://www.example.com/L1
http://www.example.com/Secret
http://www.example.com/Secret123
http://www.example.com/foobar
http://www.example.com/maret1
http://www.example.com/maret2
http://www.example.com/posted
http://www.example.com/rontest

可能是这样的,
result
是您的JSON数据:

from itertools import product

base_domains = ['http://www.google.com', 'http://www.example.com']
result = {"success":True,"code":200,"data":["Confidential","L1","Secret","Secret123","foobar","maret1","maret2","posted","rontest"],"errs":[],"debugs":[]}
for path in product(base_domains, result['data']):
    print '/'.join(path) # do whatever

http://www.google.com/Confidential
http://www.google.com/L1
http://www.google.com/Secret
http://www.google.com/Secret123
http://www.google.com/foobar
http://www.google.com/maret1
http://www.google.com/maret2
http://www.google.com/posted
http://www.google.com/rontest
http://www.example.com/Confidential
http://www.example.com/L1
http://www.example.com/Secret
http://www.example.com/Secret123
http://www.example.com/foobar
http://www.example.com/maret1
http://www.example.com/maret2
http://www.example.com/posted
http://www.example.com/rontest

Thanx表示您的输入。Thanx表示您的输入。我之前已经这样做了,但由于json中的列表会不时发生变化,我希望在不将列表硬编码到脚本中的情况下解析结果。@user2548131不硬编码列表<代码>结果=json.loads(文本)或者无论您如何获取数据……我喜欢这个示例,所以我想打印每个URL中的json字符串,我该怎么做?我以前已经这样做过,但由于json中的列表会不时更改,因此我希望在不将列表硬编码到脚本中的情况下解析结果。@user2548131不要硬编码列表
result=json.loads(text)
或者不管您如何获取数据……我喜欢这个示例,所以我想打印每个URL的json字符串,我该怎么做?
from itertools import product

base_domains = ['http://www.google.com', 'http://www.example.com']
result = {"success":True,"code":200,"data":["Confidential","L1","Secret","Secret123","foobar","maret1","maret2","posted","rontest"],"errs":[],"debugs":[]}
for path in product(base_domains, result['data']):
    print '/'.join(path) # do whatever

http://www.google.com/Confidential
http://www.google.com/L1
http://www.google.com/Secret
http://www.google.com/Secret123
http://www.google.com/foobar
http://www.google.com/maret1
http://www.google.com/maret2
http://www.google.com/posted
http://www.google.com/rontest
http://www.example.com/Confidential
http://www.example.com/L1
http://www.example.com/Secret
http://www.example.com/Secret123
http://www.example.com/foobar
http://www.example.com/maret1
http://www.example.com/maret2
http://www.example.com/posted
http://www.example.com/rontest