Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Alex_Ooi
Helper IV
Helper IV

Raspado web para mostrar todas las filas en Power Query

Hola a todos

Tengo la tarea de raspar el índice compuesto histórico disponible en Yahoo Finanzas. Tomemos un ejemplo de NASDAQ con la siguiente url: https://finance.yahoo.com/quote/%5EIXIC/history?period1=1570147200&period2=1601769600&interval=1d&fi...

Fecha de inicio: 4/10/2019

Fecha de finalización: 4/10/2020

Sin embargo, noté un problema en el que, de forma predeterminada, la dirección URL solo muestra las primeras 100 filas. Solo se expandirá cuando se desplace hacia abajo en el sitio web. Como tal, el resultado de mi código sólo devuelve la fecha más temprana de 13/5/2020 (mientras que obviamente espera que la fecha más temprana de la tabla sea 4/10/2019).

Alex_Ooi_0-1601897154205.png


No estoy familiarizado con CSS en línea y por desgracia no pude entender la mayoría de los artículos que pude encontrar. Sospecho que podría usar el segundo argumento opcional en Web.BrowserContents( ) mediante la función WaitFor. He inspeccionado el elemento CSS del sitio web y me di cuenta de que lo único que cambia antes de que la tabla se muestre completamente en la web es el elemento de clase. No sé cómo agregar eso a mi código.

<html id="atomic" class="chrome desktop JsEnabled themelight layoutEnhance(TwoColumnLayout) CollapsibleUh onDemandFocusSupport hasScrolled scrollDown HideNavrail" lang="en-US">

Espero que alguien aquí pueda ayudarme. A continuación se muestra mi código M completo.

Dejar
    Origen: Web.BrowserContents("https://finance.yahoo.com/quote/%5EIXIC/history?period1-1577836800&period2-1609372800&interval-1d&filter-history&frequency-1d"),
    "Tabla extraída de Html" - Html.Table(Fuente,
        "Columna1",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna 2",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna3",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna4",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna5",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna6",
        "MESA. W-(100-%-). M-(0)-) > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3)
            + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(2),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3)
            + TD:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(2),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
        
"Columna7",
        "MESA. W-(100-%-). M-(0)- > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3)
            + TH:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(2)
            + TH:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(1),
        Mesa. W-(100-%-). M-(0)-) > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(7)
            + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(6)
            + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(5)
            + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(4)
            + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(3)
            + TD:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(2)
            + TD:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(1),
        Mesa. W-(100-%-). M-(0-) > * > TR > TD[colspan-"""7"]:not([rowspan]):nth-child(1):nth-last-child(1)"
    [RowSelectorTM"TABLE. W-(100-%-). (0) > * > TR"]),
    "Encabezados Promocionados" - Table.PromoteHeaders(-"Tabla extraída de Html", [PromoteAllScalars-true]),
    "Columnas eliminadas" - Table.RemoveColumns("Encabezados Promocionados","Alto", "Bajo", "Adj Close**")),
    "Columnas renombradas" - Table.RenameColumns("Columnas eliminadas","Cerrar*", "Cerrar" )
    "Tipo de cambio" - Table.TransformColumnTypes('"Columnas renombradas",'Fecha', tipo fecha', ''Abrir', 'número de tipo', ''Cerrar', 'número de tipo', '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    "Errores eliminados" - Table.RemoveRowsWithErrors(-"Changed Type", ?"Date"-),
    "Filas ordenadas" - Table.Sort("Errores eliminados", "Fecha", Orden.ascendente)
En
    "Filas ordenadas"

Gracias

saludos

Alex

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hola Alex, nota el enlace de descarga a la derecha!

• Csv.Document(Web.Contents("https://query1.finance.yahoo.com/v7/finance/download/%5EIXIC?period1=1570147200&period2=1601769600&i..."),[Delimitador",", Columnas 7, Codificación 1252, QuoteStyle-QuoteStyle.None])

¡Dale una oportunidad a lo de arriba y eso debería tirar de todo!

View solution in original post

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hola, ¿qué pasa si el número de página está oculto en los metadatos, por ejemplo: https://dailymed.nlm.nih.gov/dailymed/services/v2/ndcs

, esto solo me dará los primeros 100 discos... ¿Alguna idea?

Anonymous
Not applicable

Hola Alex, nota el enlace de descarga a la derecha!

• Csv.Document(Web.Contents("https://query1.finance.yahoo.com/v7/finance/download/%5EIXIC?period1=1570147200&period2=1601769600&i..."),[Delimitador",", Columnas 7, Codificación 1252, QuoteStyle-QuoteStyle.None])

¡Dale una oportunidad a lo de arriba y eso debería tirar de todo!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.