我有这个代码,我有2个包含产品名称及其ID(product_id)的列表(product_name)
from bottle import route, run, response
import urllib2
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
from urlparse import urlparse
import json
import sys
import csv
import re
@route('/hello')
def hello():
text=list();
link=list();
req = urllib2.Request("http://www.amazon.com",
headers={"Content-Type": "application/json"})
html=urllib2.urlopen(req).read()
soup = BeautifulSoup(html)
last_page = soup.find('div', id="nav_subcats")
for elm in last_page.findAll('a'):
texts = elm.text
links = elm.get('href')
links = links.partition("&node=")[2]
text.append(texts)
link.append(links)
alltext=list();
for i,j in zip(text,link):
alltext.append({"name":i,"id":j})
return(alltext)
run(host='localhost', port=8080, debug=True)
这个只返回我的大括号中的最后一个产品名称和产品ID。如何在json中获得完整列表,当我打印我得到完整列表
alldetail=list();
for i,j in zip(product_name,product_id):
alltext.append({"name":i,"id":j})
print alldetail
我如何获得所有产品名称和ID?