0
import cgi

data = 'next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&'

x = cgi.parse_qs(data)

next_list = x['next']

我被困在如何用 for y in x 或类似的东西来获得所有“下一个”。

有任何想法吗?

4

3 回答 3

1
import cgi

data = 'next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&'

x = cgi.parse_qs(data)

next_list = x['next']

for i in range(len(x['next'])) :
    print x['next'][i]
于 2013-08-12T13:54:52.697 回答
0

您可以使用普通的旧列表切片,而不是导入另一个库:

data = 'next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&next=/contact/200/106260296&'

next_list = [x[:-1] for x in data.split('next=')[1:]]

现在next_list看起来像这样:['/contact/200/106260296', '/contact/200/106260296', '/contact/200/106260296', '/contact/200/106260296']

于 2013-08-12T13:56:30.240 回答
0
my_list = [j.split('/')[1:] for j in
           [e.split('/contact')[1] for e in cgi.parse_qs(data)['next']]
          ]

然后您可以执行以下操作:

for x, y in my_list:
    print x, y

输出:

200 106260296
200 106260296
200 106260296
200 106260296
于 2013-08-12T14:13:56.343 回答