コード例 #1
0
def iniciarProcesoEx(tipoBusqueda):
    global root, numTotalUrl, links, llaves, contador
    direccion = obtenerDireccion()
    copia = url(direccion)
    links.append(copia)
    llaveAux = hashlib.md5(copia.dir.encode("utf-8"))
    llaves[str(llaveAux.hexdigest())] = numTotalUrl
    #contador += 1
    numTotalUrl += 1
    rootParse = urlparse(direccion)
    if rootParse.path[0] == "w":
        root = rootParse.path
    else:
        root = rootParse.netloc

    aux = urlparse(links[0].dir)
    if aux.path[0] == "w":
        nombre = aux.path
    else:
        nombre = aux.netloc
    nombre = nombre + aux.path
    nombre = nombre.replace(".", "")
    nombre = nombre.replace("/", "")
    nombre = nombre + str(tipoBusqueda)

    if os.path.isfile(nombre + ".pickle"):
        abrirArchivo(tipoBusqueda)
    else:
        t0 = time()
        busquedaExclusiva(contador, t0)
コード例 #2
0
def iniciarProcesoPr(tipoBusqueda):
    global root, numTotalUrl, links, llaves, contador, profundidadDeseada
    direccion = obtenerDireccion()
    copia = url(direccion)
    links.append(copia)
    llaveAux = hashlib.md5(copia.dir.encode("utf-8"))
    llaves[str(llaveAux.hexdigest())] = numTotalUrl
    #contador += 1
    numTotalUrl += 1
    rootParse = urlparse(direccion)
    if rootParse.path[0] == "w":
        root = rootParse.path
    else:
        root = rootParse.netloc

    profundidadDeseada = input("Profundidad hasta la que desea buscar: ")
    profundidadDeseada = str(profundidadDeseada)
    aux = urlparse(links[0].dir)
    if aux.path[0] == "w":
        nombre = aux.path
    else:
        nombre = aux.netloc
    nombre = nombre + aux.path
    nombre = nombre.replace(".", "")
    nombre = nombre.replace("/", "")
    nombre = nombre + str(tipoBusqueda) + "_" + str(profundidadDeseada)
    profundidadDeseada = int(profundidadDeseada)
    if os.path.isfile(nombre + ".pickle"):
        abrirArchivoPr(tipoBusqueda)
    else:
        t0 = time()
        busquedaProfundidad(contador, t0)
コード例 #3
0
def extraccionEx(lectura, aux1):
    global numTotalUrl, links, llaves, numRepeticiones, cantidadProfundidad
    global root
    for link in lectura.xpath('//a/@href'):  # busca el tag href en el html
        aux2 = url(link)
        if aux2.dir[0:4] != "http":
            if aux2.dir[0] != "/":
                aux2.dir = (aux1 + aux2.dir)
            else:
                aux2.dir = (aux1[0:-1] + aux2.dir)
        if contador < cantidadProfundidad:
            aux2.profundidad = profundidad + 1
        #print("%d. " %(numTotalUrl)+ aux2.dir)   #Revisa los links que estan siendo checados
        llaveAux = hashlib.md5(aux2.dir.encode("utf-8"))
        if str(llaveAux.hexdigest()
               ) not in llaves:  #Revisa la existencia de llave
            auxParse = urlparse(aux2.dir)
            if auxParse.path and auxParse.netloc not in paginasEvitar:
                if root in aux2.dir:
                    links.append(aux2)
                    #direcciones.append(aux2.dir)
                    print("%d. " % (numTotalUrl) + aux2.dir)
                    llaves[str(llaveAux.hexdigest())] = numTotalUrl
                    numTotalUrl = numTotalUrl + 1
        else:
            indiceElemento = llaves.get(str(llaveAux.hexdigest()))
            #print(indiceElemento)   #Checar indice del elemento en el diccionario llaves
            respaldo = links[indiceElemento - 1]
            respaldo.repeticiones += 1
            #print(respaldo.dir) #Checar el contenido que se esta extrayendo a partir de la llave
            links[indiceElemento - 1] = respaldo
            numRepeticiones += 1  #Cuenta las repeticiones totales