2017-12-31 364 views
0

html 파일을 작성하는 작은 스크립트를 작성하려고하는데이 파일에는 여러 제품에 대한 정보가있는 두 개의 행이 들어있는 테이블이 있어야합니다. 하지만 지금은이 테이블이 이전 입력 데이터에 따라 여러 번 반복 될 필요가 있기 때문에 html 코드가 포함 된 함수를 곱할 수는 있지만 실제로 작동하지 않는다고 생각했습니다. 사실,이전 입력에 따라 곱하기 함수

입력 ---> 얼마나 많은 테이블 : 3

을 약간의 도움이 나쁘지 않을 것 때문에 여기에서하고 m는 ...

이 내가 원하는 것입니다 당신이 HTML 파일에 기록 중복 데이터가 필요한 경우 0

그래서 HTML 출력 파일이 여기에이

<-- TABLE 1 --> 
<table> 
    <tr> 
    <td colspan="4" height="30"></td> 
    </tr> 
    <tr> 
    <td width="50" class="width6p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></a></td> 
    <td width="30" class="width3p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></a></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    </tr> 
</table> 
<-- TABLE 2 --> 
<table> 
    <tr> 
    <td colspan="4" height="30"></td> 
    </tr> 
    <tr> 
    <td width="50" class="width6p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></a></td> 
    <td width="30" class="width3p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></a></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    </tr> 
</table> 
<-- TABLE 3 --> 
<table> 
    <tr> 
    <td colspan="4" height="30"></td> 
    </tr> 
    <tr> 
    <td width="50" class="width6p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://site/image/CODEPRODUCT_1" width="230" alt="DESCRIPTION_1" style="display:block" border="0" class="width90p"/></a></td> 
    <td width="30" class="width3p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://site/image/CODEPRODUCT_2" width="230" alt="DESCRIPTION_2" style="display:block" border="0" class="width90p"/></a></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_1</span ><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_1</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-1</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_1</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">DESCRIPTION_2</span><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14"> DESCRIPTION_2</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: CODEPRODUCT_-2</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">PRICE_2</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_1" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/site/product/CODEPRODUCT_2" target="_blank"><img src="http://www.site/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    </tr> 
</table> 

처럼 보일 것이다 것은 내 파이썬 코드

import locale 
import requests 
import urlparse 
import json 

def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod): 

    f = open('mkt-output.html','w') 
    f.write(bloque_prod) 
    f.close() 

if __name__ == '__main__': 
    sku_01 = raw_input('Ingrese SKU: ') 
    desc_01 = raw_input('Descripcion de SKU: ') 
    sku_precio_1 = raw_input('Precio de SKU: ') 
    sku_02 = raw_input('Ingrese SKU: ') 
    desc_02 = raw_input('Descripcion de SKU: ') 
    sku_precio_2 = raw_input('Precio de SKU: ') 
    bloque_prod = """<table> 
    <tr> 
    <td colspan="4" height="30"></td> 
    </tr> 
    <tr> 
    <td width="50" class="width6p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/product/{}" target="_blank"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></a></td> 
    <td width="30" class="width3p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/product/{}" target="_blank"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></a></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: {}-{}</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">{}</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: {}-{}</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">{}</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/product/{}" target="_blank"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/product/{}" target="_blank"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    </tr> 
</table>""".format(sku_01, 
    sku_01, 
    desc_01, 
    sku_02, 
    sku_02, 
    desc_02, 
    ' '.join(desc_01.split()[0:3]), 
    ' '.join(desc_01.split()[3:-1]), 
    desc_01.split()[-1], 
    sku_01[0:-1], 
    sku_01[-1], 
    sku_precio_1, 
    ' '.join(desc_02.split()[0:3]), 
    ' '.join(desc_02.split()[3:-1]), 
    desc_02.split()[-1], 
    sku_02[0:-1], 
    sku_02[-1], 
    sku_precio_2, 
    sku_01, 
    sku_02) 

html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod) 
+1

'format()'에 의해 반환 된 문자열에 요청 된 반복 횟수를 곱합니다. –

답변

0

, 당신은 단순히 html() 기능 쓰기를 가질 수 곱하여 변수 bloque_prod 여러번 :

def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables): 

    f = open('mkt-output.html','w') 
    f.write(bloque_prod * tables) 
    f.close() 

주 변수 01,233,693,645 첨가 테이블 중복 수는입니다.

그런 다음, tables__main()__에서 변수 정의 :

tables = input('Tables: ') 

을 ... 그리고 당신이 html()

html(sku_01, desc_01, sku_precio_1, sku_02, desc_02, sku_precio_2, bloque_prod,tables) 

를 호출 마지막 줄에 tables을 추가하면 다른 테이블을 작성 찾고 계십니까? 가 현재 인쇄되고있는 테이블에 주석을 달 필요가 있는지

또한, 당신은 추가 할 수있는 문이의 경우 : 1로 시작하는 번호를 원한다면

def html(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2,bloque_prod,tables): 
    f = open('mkt-output.html','w') 
    rawHTML = "" 
    for table in range(0, tables): 
     rawHTML += ("\n<-- TABLE " + str(table) + " -->\n" + bloque_prod) 
    f.write(rawHTML) 
    f.close() 

(방금 str(table)을 변경할 것 ~ str(table + 1))

- EDIT-- 다른 값으로 표를 만드는 것처럼 보입니다. 나는 이렇게 프로그램을 다시 작성할 것이다.

import locale 
import requests 
import urlparse 
import json 

def createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2): 
    bloque_prod = """<table> 
    <tr> 
    <td colspan="4" height="30"></td> 
    </tr> 
    <tr> 
    <td width="50" class="width6p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/product/{}" target="_blank"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></a></td> 
    <td width="30" class="width3p"></td> 
    <td width="260" class="width44p"><a href="http://www.site/product/{}" target="_blank"><img src="http://site/images/{}" width="230" alt="{}" style="display:block" border="0" class="width90p"/></a></td> 
    </tr> 
    <tr> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">{}</span ><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: {}-{}</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">{}</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    <td></td> 
    <td class="font14" valign="top" style=" font-size: 16px; inline-height:0px; font-family:Helvetica, sans-serif; font-weight:lighter; color:#666666; line-height:130%; padding:10px 0px;"> 
     <span style="font-weight: bold; color:#008EAA" class="font14">{}</span><br /> 
     <span style="font-weight: bold; color:#008EAA; font-size:14px;" class="font14">{} {}</span><br/> 
     <span style="font-size:12px;" class="font12">SKU: {}-{}</span><br /> 
     <span style="font-size:18px;" class="font14">$ </span> 
     <span style="font-size:24px; line-height:30px;" class="font20">{}</span> 
     <span style="font-size:12px; text-transform: uppercase;" class="font10"> C/U</span> <br> 
    </td> 
    </tr> 
    <tr> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/product/{}" target="_blank"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    <td></td> 
    <td style="inline-height:0px;padding-top:4px;"><a href="http://www.site/product/{}" target="_blank"><img src="http://www.site/templates/images/loquiero_med.png" width="142" title="Ver producto" style="display:block" border="0" class="width115"/></a></td> 
    </tr> 
</table>""".format(sku_01, 
    sku_01, 
    desc_01, 
    sku_02, 
    sku_02, 
    desc_02, 
    ' '.join(desc_01.split()[0:3]), 
    ' '.join(desc_01.split()[3:-1]), 
    desc_01.split()[-1], 
    sku_01[0:-1], 
    sku_01[-1], 
    sku_precio_1, 
    ' '.join(desc_02.split()[0:3]), 
    ' '.join(desc_02.split()[3:-1]), 
    desc_02.split()[-1], 
    sku_02[0:-1], 
    sku_02[-1], 
    sku_precio_2, 
    sku_01, 
    sku_02) 
    return bloque_prod 

if __name__ == "__main__": 
    f = open('mkt-output.html','w+') # Open file in w+ mode so we can append to the end 
    for table in range(0,input("Tables: ")): 
     print ("--Table "+str(table)+"--") 
     sku_01 = raw_input('Ingrese SKU: ') 
     desc_01 = raw_input('Descripcion de SKU: ') 
     sku_precio_1 = raw_input('Precio de SKU: ') 
     sku_02 = raw_input('Ingrese SKU: ') 
     desc_02 = raw_input('Descripcion de SKU: ') 
     sku_precio_2 = raw_input('Precio de SKU: ') 
     f.write(createTable(sku_01,desc_01,sku_precio_1,sku_02,desc_02,sku_precio_2)) 
    f.close() 

희망이있다.

+0

이걸 시도 할 것입니다.하지만이 정보는 내가 지정한만큼 많은 시간 동안 동일한 정보를 가진 테이블을 인쇄 할 것입니다. 특정 테이블에 여러 번 입력을 지정했지만 다른 정보로 테이블을 반복하려면 테이블의 동일한 템플리트에 다른 제품을 추가 할 수 있습니다. – Reezppo

+0

수용 할 수 있도록 내 대답이 업데이트되었습니다. –

+0

완벽 ... 당신은 정말 대단히 감사합니다 .... – Reezppo