HG-map
GIS, dev & data

Menu

  • Blog
  • Tutos
  • Astuces
  • À propos de moi
  • Réalisations
  • Contact
SPF Zone isochrone Symfony Geonetwork Regex PHP Digital marketing CARMEN KML WMS Recherche participative Open Street Map Postgres Open Dbase INSPIRE Talend Emailing Python SQL SMTP
  • Identifiant oublié ?
  • Mot de passe oublié ?

Auto submit a form with Python, Selenium and Chromium

Détails
22 mai 2022
1652
  • Database
  • Access
  • XML
  • Python
  • Digital marketing
  • Excel
  • Selenium
  • Chromium

SeleniumHere 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.

Auto submit a form with Python, Selenium and Chromium

Data management with Python, Pandas, Matplotlib and Openpyxl

Détails
11 mai 2022
18771
  • Python
  • Excel
  • matplotlib
  • openpyxl

Pandas logoPandas 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

Quelques regex sur Notepad

Détails
28 avril 2022
25963
  • Database
  • SQL
  • Data mining
  • Web scraping
  • Notepad
  • Regex

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.

Quelques regex sur Notepad

Tutoriel avancé QGIS et Python

Détails
11 avril 2022
27065

Qgis3PythonInteropé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).

Tutoriel avancé QGIS et Python

Web scraping with Python and BeautifulSoup

Détails
25 avril 2021
1325
  • Data mining
  • Python
  • Web scraping
  • Digital marketing
  • BeautifulSoup

Beautiful SoupLet'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")

Web scraping with Python and BeautifulSoup

Récupération de données sur le web

Détails
25 avril 2021
28865
  • Database
  • MySQL
  • PHP
  • SQL
  • Web scraping
  • Digital marketing

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 :

Récupération de données sur le web

  1. Acymailing, mass sending et bonnes pratiques
  2. Cryptage d'emails en MD5 - exemples d'utilisation en marketing digital
  3. Zones de chalandise avec QGIS, Python, l'API ORS et les données OSM, IGN et INSEE
  4. SQL Automatic deduplication

Page 1 sur 5

  • 1
  • 2
  • 3
  • 4
  • ...

Haut de page

© 2022 HG-Map