venerdì 1 maggio 2020

PYTHON - INTERROGATE THE WEB WITH APIs

With python's REQUEST and JSON module it's simple. Below is an example of a query to the GNEWS.IO API
This very simple script allows you to search for articles related to the keywords you enter, using the GNEWS.IO API

import requests
import json
#http://gnews.io
api_token=''#here your gnews api

keywords=input('Parole chiave:')
indirizzo='https://gnews.io/api/v3/search?q='+keywords+'&token='+api_token
print(indirizzo)
r=requests.get(indirizzo)
file=r.text
output=json.loads(file)
for i in range(len(output['articles'])):
    print('Articoli: '+output['articles'][i]['title'])
    print('Descrizione: '+output['articles'][i]['description'])
    print('URL: '+output['articles'][i]['url'])
    print('Pubblicato il: '+output['articles'][i]['publishedAt'])

The web is full of APIs that can be used to collect any type of data.
If you like the blog remember to support my work through gofundme or by sending cryptocurrencies. Thanks

Nessun commento:

Posta un commento