2017-04-17 11 views
-5

Ich habe eine Reihe von URLs, die ich wie folgt replizieren muss.Wie erstelle ich eine Liste wie die folgende?

https://wipp.edmundsassoc.com/Wipp/?wippid=*1205* 

Die 1205 ist variabel die endgültigen Ausgaben wie

"https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage1" 
................................................#taxpage2" 
................................................#taxpage3 
................................................#taxpage4 

und so weiter suchen müssen. Ich habe eine Liste von URLs ohne den "#taxpage" Teil und die Liste, wie viele Steuerseiten jeder haben sollte. Ich möchte eine Liste aller möglichen Seiten für jede URL erstellen. Vielen Dank für jede Hilfe .... völlig neu für die Codierung und jede Hilfe wird sehr geschätzt.

Antwort

1

Sie können str.format verwenden, um die #taxpage Nummer in einer Liste Verständnis hinzufügen

>>> s = r'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage{}' 
>>> [s.format(i) for i in range(1, 5)] 
    ['https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage1', 
    'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage2', 
    'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage3', 
    'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage4'] 
0

Sie können diese mit Hilfe Liste Verständnis tun:

In [1]: urls = ['https://wipp.edmundsassoc.com/Wipp/?wippid=1205', 
       'https://wipp.edmundsassoc.com/Wipp/?wippid=1206'] 

In [2]: ["{}#taxpage{}".format(url, page_num) for page_num in xrange(1, 4) for url in urls] 
Out[2]: 
['https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage1', 
'https://wipp.edmundsassoc.com/Wipp/?wippid=1206#taxpage1', 
'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage2', 
'https://wipp.edmundsassoc.com/Wipp/?wippid=1206#taxpage2', 
'https://wipp.edmundsassoc.com/Wipp/?wippid=1205#taxpage3', 
'https://wipp.edmundsassoc.com/Wipp/?wippid=1206#taxpage3'] 
Verwandte Themen