我不知道问题是什么,但它会多次打印同样的东西。如果有人可以帮助我,我们将不胜感激。谢谢
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)
答案 0 :(得分:0)
您的查找结果太高,因此您最终会在文档中获取文档中每个ID的所有标题。在每个变体中找到发现。
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("variant"):
cart = 'http://'+parsed.netloc+'/cart/' +variant.id.text+':1'
size = variant.find("title")
print(cart, size.text)
答案 1 :(得分:-1)
您的print(cart, size.text)
不应该是print(size, size.text)
吗?