2017-02-16 3 views
-2

Ich weiß nicht, was das Problem ist, aber es auf dem gleichen Ding mehrere Male drucken. Wenn mir jemand helfen kann, wird es sehr geschätzt. DankeDrucken Sie die gleiche Sache mehrmals

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

Was soll es drucken? Und wie soll das aus der Eingabe abgeleitet werden? Was wird gedruckt? – interjay

+0

Es soll so drucken: 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

Antwort

0

Ihre Suche ist zu hoch, sodass Sie alle Titel im Dokument für jede ID im Dokument erhalten. Tue die Funde in jeder Variante.

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) 
+0

vielen Dank. – EdBiz

-1

Sollte Ihr print(cart, size.text) nicht print(size, size.text) sein?

+0

Nein, weil ich drucken möchte die Links vom Warenkorb – EdBiz

Verwandte Themen