Differences between revisions 1 and 11 (spanning 10 versions)
Revision 1 as of 2017-03-03 14:19:00
Size: 489
Editor: uid
Comment:
Revision 11 as of 2017-03-15 10:19:25
Size: 2160
Editor: uid
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#format wiki
#language it
Line 11: Line 13:
Serie di pomeriggi di sperimentazione libera, segue workshop rivolto al pubblico.

== Temi ==
Line 15: Line 21:
  * Beautiful-soup per il parsing delle pagine   * Beautiful-soup e/o lxml per il parsing delle pagine
  * Web spider con scrapy
Line 17: Line 24:

== Riferimenti Sparsi ==
 * https://elitedatascience.com/python-web-scraping-libraries
 * https://first-web-scraper.readthedocs.io/en/latest/
 * https://medium.com/@kaismh/extracting-data-from-websites-using-scrapy-e1e1e357651a
 * https://deshmukhsuraj.wordpress.com/2015/03/08/anonymous-web-scraping-using-python-and-tor/

== Terminale ==

=== curl ===
{{{
curl "http://www.example.com"
}}}
esegue una GET e ne stampa l'output

{{{
curl "http://www.example.com" > out.html
}}}
ora l'output viene reindirizzato sul file ''out.html''

=== wget ===
{{{
wget "http://www.example.com/index.html"
}}}
salva in contenuto in ''index.html''

{{{
wget -r "http://www.example.com/"
}}}
salva '''tutto''' il contenuto del sito nella directory corrente

=== Python ===
{{{
python3 script.py
}}}
esegue uno script

{{{
python3 script.py > out.txt
}}}
esegue uno script e ne salva l'output in ''out.txt''

== Codice ==
 * Stampa l'elenco degli spazi di Macao:
 {{{#!highlight python3
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup

url = "http://www.macaomilano.org/spip.php?rubrique18"
r = requests.get(url)
page = r.text

soup = BeautifulSoup(page, "html.parser")

h2s = soup.findAll("h2")
spazi = [h2.text for h2 in h2s]

print("\n".join(spazi))
}}}

 * Fake user-agent:
 {{{#!highlight python3
headers = requests.utils.default_headers()
headers.update({"User-Agent": "Mozilla/5.0"})

r = requests.get(url, headers=headers)
}}}

Costruzione Utensili

La Cultura è la nostra Natura, siamo cacciatori e raccoglitori in un mondo di dati.

Prerequisiti

  • Un'idea vaga di HTML
  • Saper scrivere, o anche solo leggere un qualsiasi linguaggio

Programma

Serie di pomeriggi di sperimentazione libera, segue workshop rivolto al pubblico.

Temi

Ancora da definire, ma a grandi linee:

  • Orientarsi con l'inspector del Browser
  • Rudimenti di web scraping con Python:
    • GET e fake-user agent con requests
    • Beautiful-soup e/o lxml per il parsing delle pagine
    • Web spider con scrapy
  • wget e qualcosa di bash?

Riferimenti Sparsi

Terminale

curl

curl "http://www.example.com"

esegue una GET e ne stampa l'output

curl "http://www.example.com" > out.html

ora l'output viene reindirizzato sul file out.html

wget

wget "http://www.example.com/index.html"

salva in contenuto in index.html

wget -r "http://www.example.com/"

salva tutto il contenuto del sito nella directory corrente

Python

python3 script.py

esegue uno script

python3 script.py > out.txt

esegue uno script e ne salva l'output in out.txt

Codice

  • Stampa l'elenco degli spazi di Macao:
       1 #!/usr/bin/env python3
       2 import requests
       3 from bs4 import BeautifulSoup
       4 
       5 url = "http://www.macaomilano.org/spip.php?rubrique18"
       6 r = requests.get(url)
       7 page = r.text
       8 
       9 soup = BeautifulSoup(page, "html.parser")
      10 
      11 h2s = soup.findAll("h2")
      12 spazi = [h2.text for h2 in h2s]
      13 
      14 print("\n".join(spazi))
    
  • Fake user-agent:
       1 headers = requests.utils.default_headers()
       2 headers.update({"User-Agent": "Mozilla/5.0"})
       3 
       4 r = requests.get(url, headers=headers)
    

CostruzioneUtensili (last edited 2017-03-18 01:13:13 by subnixr)