Quelques regex sur Notepad
- Détails
- 28263
Les expressions régulières (regex) sur Notepad++ sont très pratiques pour standardiser un fichier de données avant import par exemple, récupérer des données, corriger des chaînes particulières, avec des conditions, etc...
Ici quelques astuces propres à mon usage personnel.
Data management with Python, Pandas, Matplotlib and Openpyxl
- Détails
- 21873
Pandas is an excellent Python librarie to manage data. Barely started using it, it already solves some of my recurring needs. Matplotlib allows to create advanced charts and Openpyxl is very usefull to manage Excel files, read or generate them for example.
So here some tips for my memory and maybe for you.
Let's go learn data analysis with this 3 beautiful tools. First install or check Python and Pip, then the libraries.
pip install pandas pip install matplotlib pip install openpyxl
Data management with Python, Pandas, Matplotlib and Openpyxl
Auto submit a form with Python, Selenium and Chromium
- Détails
- 1947
Here a simple Selenium example where we go to fill then submit a form from data previously converted in XML.
I choose XML because this flat format is easy to grab with Python, and it can be created from an Excel file with Access for example. Morever, if the auto-submit crashs during the execution (it is possible even with a good code, depending on the website providing the form), Chromium will stop on the last record and you could remove the begining of the XML before to re-execute the same code (to avoid duplicates).
For those in a hurry (🧐) my code is here on GitHub. But for a full understanding just see below.
Tutoriel avancé QGIS et Python
- Détails
- 29875
Interopérabilité Python/QGIS - Principaux concepts de Python, indentation, itération, variable, méthode, boucle, fonction, condition, tuple, paramètre, argument, chaîne formatée, importation - Fonctions géométriques - Écriture de fichiers - Fonctions SIG - Génération de cartes - Standalone - Milieu alpin
Sources et liens divers :
- Tutoriel d'initiation à Python dans QGIS3 (débutant) : http://www.qgistutorials.com/fr/docs/3/getting_started_with_pyqgis.html
- Blog spécialisé d'Underdark, aka Anita Graser : https://anitagraser.com/
- Documentation QGIS : https://docs.qgis.org/3.10/en/docs/
- Documentation Python : https://docs.python.org/fr/3/
- Documentation ArcGIS/Python : https://desktop.arcgis.com/search/?q=python&language=fr
- Processing providers and algorithms : https://docs.qgis.org/3.10/en/docs/user_manual/processing_algs/
- OSMDownloader : https://github.com/lcoandrade/OSMDownloader
- QuickOSM : https://github.com/3liz/QuickOSM
- Wikidata : https://www.wikidata.org/
- Landscape Archaeology : https://landscapearchaeology.org/
- AppDividend : https://appdividend.com/
- OpenSourceOptions: https://opensourceoptions.com/
- webgeodatavore : https://webgeodatavore.com/
- QGIS StackExchange : https://gis.stackexchange.com
Tutoriel écrit sur QGIS 3.14 'Py' et Python 3.8, mais j'ai pu constater qu'il fonctionne de façon assez similaire sur des versions précédentes, ainsi que sur QGIS 3.16.
Sur des versions plus récentes comme QGIS 3.2 il semble que certaines API n'aient pas encore été portées (wikipedia et wikidata).
Web scraping with Python and BeautifulSoup
- Détails
- 1520
Let's go web scraping with Python and BeautifulSoup! Here BeautifulSoup will be able to extract formatted data from HTML and its CCS code. For confidentiality reasons, we will not name the parsed website, but a lot are built like that: pages containing record from a database use their ID in the URL. So you will to adapt the codes below to your own website and purposes.
We will use a complex website as example, where the IDs to guess are listed in a large pagination.
First, we will get the links to articles (with IDs in URLs) from all pages of the pagination, then we will store data in a CSV file, if interesting (we search emails). So we will do a loop in a loop, with a condition, but if the website you want to parse is simpler (without pagination), you will not need the first loop.
Libraries and receptacle
We start by importing some necessary libraries and creating the receptacle file for our data.
from bs4 import BeautifulSoup import requests import re import csv # CSV file to receive data out_file = open('C:/python_projects/webscraping/email.csv', 'w', encoding='cp1252') out_file.write("email" + "\n")
Récupération de données sur le web
- Détails
- 30012
Retour d'expérience sur la création d'un gentil petit robot récupérateur de données.
Bien entendu il n'y a pas de mauvaises intentions de notre part, nous ne récupérerons que des données publiques, disponibles librement sur des sites internet divers. Il ne s'agit pas de piratage ni d'aucune forme d'intrusion. Soit une forme de web scraping. La récupération automatique de données peut d'ailleurs être utile pour de nombreuses tâches très honorables (statistiques, santé, social...) ou marketing.
Nous travaillerons, dans cet exemple simple, sur un site contenant des données de contacts (email, téléphone, métier...). Certains sites considèrent ce type d'annuaire comme vendeur et mettent en avant la disponibilité de données de contact.
Nous tairons son nom de domaine, mais prenons l'exemple d'une fiche de contact à l'URL bien lisible :
http://site-indiscret.com/contacts/45988
La forme de l'URL est très standard et se termine par une chaîne numérique. Sans doute un identifiant unique ! C'est le terrain d'action idéal pour un jeune robot récupérateur de données.
Ce site au webmaster un peu pressé sera donc un bon cobaye pour notre 1er bot. Et en modifiant le script final, vous pourrez sans doute l'adapter à vos propres besoins.
Les grandes étapes d'enfantement seront les suivantes :
Page 1 sur 5