Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在init函数上使用e头,因此它只创建一次该行。非常感谢你的帮助! def main(url, destino): """ Acceso al sitio web """ soup = bs(urlopen(url), 'lxml') _Python_Csv - Fatal编程技术网

Python 在init函数上使用e头,因此它只创建一次该行。非常感谢你的帮助! def main(url, destino): """ Acceso al sitio web """ soup = bs(urlopen(url), 'lxml')

Python 在init函数上使用e头,因此它只创建一次该行。非常感谢你的帮助! def main(url, destino): """ Acceso al sitio web """ soup = bs(urlopen(url), 'lxml') ,python,csv,Python,Csv,在init函数上使用e头,因此它只创建一次该行。非常感谢你的帮助! def main(url, destino): """ Acceso al sitio web """ soup = bs(urlopen(url), 'lxml') parsed = list(urlparse.urlparse(url)) """ Acceso al archivo csv """ fileName = 'datos/datos.csv' print file

在init函数上使用e头,因此它只创建一次该行。非常感谢你的帮助!
def main(url, destino):
    """ Acceso al sitio web """
    soup = bs(urlopen(url), 'lxml')
    parsed = list(urlparse.urlparse(url))

    """ Acceso al archivo csv """
    fileName = 'datos/datos.csv'
    print fileName
    f = csv.writer(open(fileName, 'w'))
    f.writerow(["Lote", "Dato del lote", "Detalles"]) # Header

    """ Acceso a la descr. y escritura en el csv """
    description = soup.findAll(True, {'class':['description']})

    for text in description:
        loteNum = text.contents[1]
        loteDat = text.contents[3]
        detalle = text.contents[6]
        detalleE = detalle.encode("utf-8")
        print loteNum
        print loteDat
        print detalle
        f.writerow([loteNum, loteDat, detalleE])

    """ Descarga de las img. """
    for image in soup.findAll(True, {'class':['list_logo']}):
        print "Image: %(src)s" % image
        image_url = urlparse.urljoin(url, image['src'])
        filename = image["src"].split("/")[-1]
        outpath = os.path.join(destino, filename)
        urlretrieve(image_url, outpath)
def getUrl(opt, baseUrl):
    destino = "/home/ivanhercaz/monedasWiki/img"
    print "Instrucciones del script \n No te preocupes, no es complicado pero atiende a los pasos"
    print "Introduce 1 para obtener los archivos del 00001 al 00010"
    print "Introduce 2 para obtener los archivos del 00010 al 00099"
    print "Introduce 3 para obtener los archivos del 00100 al 00999"
    print "Introduce 4 para obtener los archivos del 01000 al 09999"
    print "Introduce 5 para obtener los archivos del 10000 al 19999"
    optSel = int(input(opt))
    # i es el rango
    # urlI es la transformacion de i en cadena
    # baseUrl es el enlace al sitio web de Pliego
    # url es la url completa con los parametros necesarios
    if optSel == 1:
        try:
            for i in range(0,10):
                r = str(0).zfill(4)
                urlI = str(i)
                url = baseUrl + r + urlI
                main(url, destino)
        except ValueError:
            print "Introduce el rango correcto"
    elif optSel == 2:
        try:
            for i in range(10,100):
                r = str(0).zfill(3)
                urlI = str(i)
                url = baseUrl + r + urlI
                main(url, destino)
        except ValueError:
            print "Introduce el rango correcto"
    elif optSel == 3:
        try:
            for i in range(100,1000):
                r = str(0).zfill(2)
                urlI = str(i)
                url = baseUrl + r + urlI
                main(url, destino)
        except ValueError:
            print "Introduce el rango correcto"
    elif optSel == 4:
        try:
            for i in range(1000,10000):
                r = str(0).zfill(1)
                urlI = str(i)
                url = baseUrl + r + urlI
                main(url, destino)
        except ValueError:
            print "Introduce el rango correcto"
    elif optSel == 2:
        try:
            for i in range(10000,18510):
                urlI = str(i)
                url = baseUrl + r + urlI
                main(url, destino)
        except ValueError:
            print "Introduce el rango correcto"
    elif optSel < 0:
        print "Valor inferior a 0"
    else:
        print "Algo ha salido mal"
<!-- language: python -->
def main(url, destino):
    """ Acceso al sitio web """
    soup = bs(urlopen(url), 'lxml')
    parsed = list(urlparse.urlparse(url))

    """ Acceso al archivo csv """
    fileName = 'datos/datos.csv'
    print fileName

    """ Acceso a la descr. y escritura en el csv """
    description = soup.findAll(True, {'class':['description']})

    for text in description:
        loteNum = text.contents[1]
        loteDat = text.contents[3]
        detalle = text.contents[6]
        detalleE = detalle.encode("utf-8")
        print loteNum
        print loteDat
        print detalle
        header = ["Lote", "Dato del lote", "Detalles"]
        data = [loteNum, loteDat, detalleE]
        with open(fileName, 'w') as f:
            f = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
            f.writerow(header)
            f.writerow(data)

    """ Descarga de las img. """
    for image in soup.findAll(True, {'class':['list_logo']}):
        print "Image: %(src)s" % image
        image_url = urlparse.urljoin(url, image['src'])
        filename = image["src"].split("/")[-1]
        outpath = os.path.join(destino, filename)
        urlretrieve(image_url, outpath)
for text in description:
    # ... some functionality
    data = [loteNum, loteDat, detalleE]
    with open(fileName, 'w') as f:
        f = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
        f.writerow(header)
        f.writerow(data)
with open(fileName, 'w') as f:
    f = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
    header = ["Lote", "Dato del lote", "Detalles"]
    f.writerow(header)
    for text in description:
        loteNum, loteDat, detalle = [text.contents[i] for i in (1, 3, 6)]
        detalleE = detalle.encode("utf-8")
        print loteNum, loteDat, detalle
        data = [loteNum, loteDat, detalleE]
        f.writerow(data)