SlideShare uma empresa Scribd logo
1 de 71
Baixar para ler offline
by examples
                       Scraping
                        Alexandre Gomes
Friday, May 20, 2011
http://creativecommons.org/licenses/by-nc/3.0/br/
Friday, May 20, 2011
Primeiros resultados definitivos do Censo 2010:
      população do Brasil é de 190.755.799 pessoas
      O Brasil tem 190.755.799 habitantes. É o que
      constata a Sinopse do Censo Demográfico 2010, que
      contém os primeiros resultados definitivos do XII
      Recenseamento Geral do Brasil... 29/04/2011




                       http://www.ibge.gov.br
Friday, May 20, 2011
Resumo do Censo 2010

Friday, May 20, 2011
Resumo do Censo 2010

Friday, May 20, 2011
Friday, May 20, 2011
Friday, May 20, 2011
Qual a relação entre os índices de
  alfabetização e a proporção feminina?




Friday, May 20, 2011
Exemplo
      mulheres da região               7.859.539
                              =                                 = 0.49
total de pessoas da região        7.859.539 + 8.004.915

  alfabetizados* da região             11.326.492
                              =                                 = 0.89
total de pessoas* da região            12.670.041

                                                    * acima de 10 anos de idade
Friday, May 20, 2011
E nas
      demais
     regiões?
Friday, May 20, 2011
Scraping by
Friday, May 20, 2011
                        Examples
Nokogiri


Friday, May 20, 2011
#1 Acessar a página que
                           contém o dado
                              desejado




Friday, May 20, 2011
teste




Friday, May 20, 2011
teste



  codigo


Friday, May 20, 2011
$ rspec spec/ibge_censo2010_spec.rb:8
Run filtered using {:line_number=>8}

IBGECenso2010
  should open page with "Razão de sexo,
população de homens e mulheres"

Finished in 44.4 seconds
1 example, 0 failures
$


Friday, May 20, 2011
#2 Recuperar o
                       dado desejado




Friday, May 20, 2011
Antes, entenda a
                       estrutura da página




Friday, May 20, 2011
<table>
   <thead>...</thead>
   <tfoot>
     <tr>
       <td>...</td>
       <td>...</td>
       <td>...</td>
       <td>...</td>
                       <td>...</td>
     </tr>
   </tfoot>                           Estude o caminho
   <tbody>...</tbody>                 do dado na árvore
                                            DOM
 </table>
Friday, May 20, 2011
Observe IDs e
                       classes CSS que
                       podem ser úteis.




Friday, May 20, 2011
Friday, May 20, 2011
class="td_numeros"




Friday, May 20, 2011
Friday, May 20, 2011
Friday, May 20, 2011
".td_numeros"


           [

Friday, May 20, 2011
".td_numeros"


           [           0    1          2
                        3    4          5
                        6    7          8
                        9   10         11
                       12   13         14
Friday, May 20, 2011
                       15   16         17
1º dado de que
                               precisamos.
                            (numerador da fórmula)




           [           0           1                 2
                        3           4                 5
                        6           7                 8
                        9          10                11
                       12          13                14
Friday, May 20, 2011
                       15          16                17
2º dado de que
                                     precisamos.
                                    (para o cálculo do
                                 denominador da fórmula)



           [           0    1             2
                        3    4             5
                        6    7             8
                        9   10            11
                       12   13            14
Friday, May 20, 2011
                       15   16            17
mulheres da região N              dados[5]
                                =
 total de pessoas da região N        dados[4] + dados[5]



           [           0        1                2
                        3        4                5
                        6        7                8
                        9       10               11
                       12       13               14
Friday, May 20, 2011
                       15       16               17
teste




Friday, May 20, 2011
code




Friday, May 20, 2011
$ rspec spec

IBGECenso2010
  razao de sexo
    should open page with "Razão de sexo,
população de homens e mulheres"
    should get number of women

Finished in 1.78 seconds
2 examples, 0 failures

Friday, May 20, 2011
teste




Friday, May 20, 2011
code




Friday, May 20, 2011
#3 Recuperar o
                       restante de dados
                           desejados



Friday, May 20, 2011
Friday, May 20, 2011
...
Friday, May 20, 2011
#4 Apresentação
                       Web do scrapping

Friday, May 20, 2011
application.rb




   (...)
Friday, May 20, 2011
application.rb
     (...)




Friday, May 20, 2011
index.erb




(...)

Friday, May 20, 2011
http://datavisualization.ch/tools/13-javascript-libraries-for-visualizations
Friday, May 20, 2011
me    do s
   o c har          na
         ups e s tá
  m ash          ção
        sualiza
     vi
     diferenciada
                                                    de dados

  http://datavisualization.ch/tools/13-javascript-libraries-for-visualizations
Friday, May 20, 2011
#5 Visualização
               (ainda tosca) do
                   scrapping




Friday, May 20, 2011
Friday, May 20, 2011
#6 Visualização
                       diferenciada da
                         informação




Friday, May 20, 2011
Friday, May 20, 2011
                       ?
Agora, a
                         mesma
                          coisa,
                         apenas
                          com
                       Javascript
Friday, May 20, 2011
#1 Acessar a página que
                           contém o dado
                              desejado




Friday, May 20, 2011
test




Friday, May 20, 2011
code




Friday, May 20, 2011
Friday, May 20, 2011
#2 Recuperar o
                       dado desejado




Friday, May 20, 2011
test




Friday, May 20, 2011
code




Friday, May 20, 2011
#3 Recuperar o
                       restante de dados
                           desejados



Friday, May 20, 2011
...
Friday, May 20, 2011
#4 Apresentação
                       Web do scrapping

Friday, May 20, 2011
index.html




Friday, May 20, 2011
index.html




Friday, May 20, 2011
index.html




Friday, May 20, 2011
index.html




Friday, May 20, 2011
index.html




                       (...)
Friday, May 20, 2011
index.html




                       (...)
Friday, May 20, 2011
index.html


        (...)




Friday, May 20, 2011
index.html


        (...)




Friday, May 20, 2011
http://chart.apis.google.com/chart?
  chxt=y&chbh=a&chs=500x300&cht=bvg&chco=A2C180,3D7930
     &chd=t:49,51,51,50,50|89,82,94,95,93
                       &chdl=Women|Literates&chp=0.033
Friday, May 20, 2011
código disponível em...




Friday, May 20, 2011
P&R
Friday, May 20, 2011
http://tinyurl.com/AvaliacaoSOO14




Friday, May 20, 2011
Friday, May 20, 2011

Mais conteúdo relacionado

Destaque

Opatrovanie v minikolektive(Bratislava)
Opatrovanie v minikolektive(Bratislava)Opatrovanie v minikolektive(Bratislava)
Opatrovanie v minikolektive(Bratislava)veselydomcek
 
Eskisehir Hasbahce Evleri
Eskisehir Hasbahce EvleriEskisehir Hasbahce Evleri
Eskisehir Hasbahce Evleriomcdesign
 
禅があなたをシンプルにそして楽にする
禅があなたをシンプルにそして楽にする禅があなたをシンプルにそして楽にする
禅があなたをシンプルにそして楽にする虹 父
 

Destaque (6)

Opatrovanie v minikolektive(Bratislava)
Opatrovanie v minikolektive(Bratislava)Opatrovanie v minikolektive(Bratislava)
Opatrovanie v minikolektive(Bratislava)
 
GAEO
GAEOGAEO
GAEO
 
Eskisehir Hasbahce Evleri
Eskisehir Hasbahce EvleriEskisehir Hasbahce Evleri
Eskisehir Hasbahce Evleri
 
Vesely Domcek4
Vesely Domcek4Vesely Domcek4
Vesely Domcek4
 
GAEO
GAEOGAEO
GAEO
 
禅があなたをシンプルにそして楽にする
禅があなたをシンプルにそして楽にする禅があなたをシンプルにそして楽にする
禅があなたをシンプルにそして楽にする
 

Mais de Alexandre Gomes

Construção de Software - 1º/2017
Construção de Software - 1º/2017Construção de Software - 1º/2017
Construção de Software - 1º/2017Alexandre Gomes
 
Programação Funcional com Javascript
Programação Funcional com JavascriptProgramação Funcional com Javascript
Programação Funcional com JavascriptAlexandre Gomes
 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2Alexandre Gomes
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certoAlexandre Gomes
 
Construção de Software - 1º/2016
Construção de Software - 1º/2016Construção de Software - 1º/2016
Construção de Software - 1º/2016Alexandre Gomes
 
Plano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwarePlano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwareAlexandre Gomes
 
Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Alexandre Gomes
 
Laboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoLaboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoAlexandre Gomes
 
OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.Alexandre Gomes
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certoAlexandre Gomes
 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testesAlexandre Gomes
 

Mais de Alexandre Gomes (20)

Construção de Software - 1º/2017
Construção de Software - 1º/2017Construção de Software - 1º/2017
Construção de Software - 1º/2017
 
TDDing com Javascript
TDDing com JavascriptTDDing com Javascript
TDDing com Javascript
 
Aprendendo a Aprender
Aprendendo a AprenderAprendendo a Aprender
Aprendendo a Aprender
 
Programação Funcional com Javascript
Programação Funcional com JavascriptProgramação Funcional com Javascript
Programação Funcional com Javascript
 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certo
 
Construção de Software - 1º/2016
Construção de Software - 1º/2016Construção de Software - 1º/2016
Construção de Software - 1º/2016
 
Plano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwarePlano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de Software
 
O Pensamento Ágil
O Pensamento ÁgilO Pensamento Ágil
O Pensamento Ágil
 
Manifesto 2.0
Manifesto 2.0Manifesto 2.0
Manifesto 2.0
 
Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014
 
Business Modeling
Business ModelingBusiness Modeling
Business Modeling
 
Design Thinking
Design ThinkingDesign Thinking
Design Thinking
 
Manifesto Ágil
Manifesto ÁgilManifesto Ágil
Manifesto Ágil
 
Laboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoLaboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - Apresentação
 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examples
 
OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certo
 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testes
 
Escolhas 2.0
Escolhas 2.0Escolhas 2.0
Escolhas 2.0
 

Último

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Scraping by examples