我不知道是什麼問題,但它多次保持打印同一個東西。如果有人能幫助我,將不勝感激。謝謝多次打印相同的東西
from bs4 import BeautifulSoup
from urllib.parse import urlparse
import urllib.request
req = urllib.request.Request('http://shopnicekicks.com/products/a-ma-maniere-x-diadora-n9000-mens-brown-sugar.xml')
res = urllib.request.urlopen(req)
end = res.geturl()
soup = BeautifulSoup(res, 'lxml')
parsed = urlparse(end)
for variant in soup.variants.find_all("id", {"type": "integer"}):
cart = 'http://'+parsed.netloc+'/cart/' +variant.text+':1'
for size in soup.variants.find_all('title'):
print(cart, size.text)
應該打印什麼?那麼這是如何從輸入中推導出來的呢?它實際上打印了什麼? – interjay
它假設打印像這樣: http://shopnicekicks.com/cart/23839239105:1 8 http://shopnicekicks.com/cart/23839239169:1 8.5 http://shopnicekicks.com/cart/23839239233 :1 9 http://shopnicekicks.com/cart/23839239297:1 9.5 http://shopnicekicks.com/cart/23839239361:1 10 http://shopnicekicks.com/cart/23839239425:1 10.5 http ://shopnicekicks.com/cart/23839239489:1 11 http://shopnicekicks.com/cart/23839239553:1 12 http://shopnicekicks.com/cart/23839239617:1 13 – EdBiz