Skip to content

Este paquete proporciona funciones para extraer datos de X/Twitter, incluidos tweets, usuarixs y metadatos asociados sin necesidad de usar API. || This package provides functions to extract X/Twitter data, including tweets, usuarixs and associated met

License

Notifications You must be signed in to change notification settings

agusnieto77/TweetScraperR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TweetScraperR

Project Status: Active – The project has reached a stable, usable state and is being actively developed. License: MIT

Vision general

Este paquete proporciona funciones para extraer datos de X/Twitter, incluidos tweets, usuarixs y metadatos asociados, permitiendo realizar la extracción y manejo de estos datos de manera conveniente en R. Enfocado en facilitar la recolección de datos para análisis y visualización, el paquete puede obtener tweets desde la búsqueda de X/Twitter y está construido sobre rvest, sin utilizar las API de X/Twitter. Aunque los datos rastreados no son tan limpios como los obtenidos a través de las API, el costo actual de las API hace que esta sea una alternativa flexible, gratuita y de código abierto.

This package provides functions to extract data from X/Twitter, including tweets, users, and associated metadata, allowing for convenient data extraction and handling in R. Focused on facilitating data collection for analysis and visualization, the package can obtain tweets from X/Twitter search and is built on rvest, without using the X/Twitter APIs. Although the scraped data is not as clean as that obtained through the APIs, the current cost of the APIs makes this a flexible, free, and open-source alternative.

Instalacion de la version en desarrollo

Puedes instalar la versión de desarrollo de TweetScraperR desde GitHub con:

# install.packages("devtools")
devtools::install_github("agusnieto77/TweetScraperR")

Funciones

Nombre Ciclo Descripción
closeTimeline() Cierre de Timeline.
closeTwitter() Cierre de sesión.
extractTweetsData() Extrae información relevante de tweets almacenados localmente.
getScrollExtract() Scrolea y extrae tweets.
getScrollExtractUrls() Scrolea y extrae URLs de tweets.
getTweetsData() Recupera datos de tweets a partir de URLs.
getTweetsFullSearch() Recupera tweets desde la búsqueda avanzada.
getTweetsHashtags() Recupera los hashtags de la columna 'texto'.
getTweetsHistoricalHashtag() Recupera tweets históricos con un hashtag específico.
getTweetsHistoricalHashtagFor() Recupera tweets históricos con un hashtag específico en un ciclo for.
getTweetsHistoricalSearch() Recupera tweets históricos con un término específico.
getTweetsHistoricalSearchFor() Recupera tweets históricos con un término específico en un ciclo for.
getTweetsHistoricalTimeline() Recupera tweets históricos de un timeline.
getTweetsHistoricalTimelineFor() Recupera tweets históricos de un timeline en un ciclo for.
getTweetsImages() Descarga las imágenes posteadas en los tweets.
getTweetsImagesAnalysis() Analiza las imágenes posteadas en los tweets.
getTweetsSearchStreaming() Recupera tweets en tiempo real.
getTweetsSearchStreamingFor() Itera la recuperación de tweets en tiempo real.
getTweetsSentiments() Analizador de sentimientos.
getTweetsTimeline() Recupera tweets de un timeline.
getUrlsHistoricalTimeline() Recupera URLs de tweets históricos de un timeline.
getUrlsSearchStreaming() Recupera URLs de tweets en tiempo real.
getUrlsTweetsReplies() Recupera las URLs de las respuestas a un tweet.
getUrlsTweetsSearch() Recupera URLs de tweets por búsqueda.
getUrlsTweetsTimeline() Recupera URLs de tweets de un timeline.
getUsersData() Recupera datos de users a partir de URLs.
getUsersFullData() Recupera datos completos de users a partir de URLs.
HTMLImgReport() Crea una visualización HTML interactiva de imágenes analizadas.
openTimeline() Accede al Timeline de un/a usuario/a.
openTwitter() Inicio de sesión.
plotEmojis() Hace un gráfico de barras en base a la columna 'emoticones'.
plotEmojisPNG() Hace un gráfico de barras en base a la columna 'emoticones' con los PNG de los emojis.
plotTime() Hace un gráfico de líneas en base a la columna 'texto'.
plotWords() Hace una nube de palabras en base a la columna 'texto'.

Uso de las funciones del paquete {TweetScraperR}

# Cargamos la librería
require(TweetScraperR)

# Con la función getTweetsSearchStreaming() recolectamos en tiempo real los  
# tweets que mencionan el término de búsqueda, en este ejemplo es un hashtag.
# Esta función guarda un rds con los tweets y algunos metadatos.

urls_hashtagRstats <- getTweetsSearchStreaming(search = "#RStats", n_tweets = 20)
#> Inició la recolección de tweets.
#> Finalizó la recolección de tweets.
#> Datos procesados y guardados.
#> Tweets únicos recolectados: 8
urls_hashtagRstats
#> # A tibble: 8 × 6
#>   art_html  fecha               user             tweet url   fecha_captura      
#>   <list>    <dttm>              <chr>            <chr> <chr> <dttm>             
#> 1 <chr [1]> 2024-10-09 13:39:56 @BiochemistTomas "\nW… http… 2024-10-09 10:53:25
#> 2 <chr [1]> 2024-10-09 13:22:23 @RodgersData     "\nA… http… 2024-10-09 10:53:25
#> 3 <chr [1]> 2024-10-09 12:17:43 @rcityviews      "\nI… http… 2024-10-09 10:53:25
#> 4 <chr [1]> 2024-10-09 12:16:37 @d_mykhailyshyna "\nT… http… 2024-10-09 10:53:25
#> 5 <chr [1]> 2024-10-09 12:04:54 @cyberpuck01     "\nC… http… 2024-10-09 10:53:25
#> 6 <chr [1]> 2024-10-09 11:59:31 @leonardohansa   "\nD… http… 2024-10-09 10:53:25
#> 7 <chr [1]> 2024-10-09 11:58:01 @BjnNowak        "\nT… http… 2024-10-09 10:53:25
#> 8 <chr [1]> 2024-10-09 11:57:34 @HackCyber80     "\nC… http… 2024-10-09 10:53:25
# Con la función getTweetsHistoricalHashtag(), recuperamos tweets históricos 
# que contengan el hashtag #rstats y los imprimimos en pantalla

tweets_historicos <- getTweetsHistoricalHashtag("#rstats", n_tweets = 20)
#> Inició la recolección de tweets.
#> Finalizó la recolección de tweets.
#> Procesando datos...
#> Datos procesados y guardados.
#> Tweets únicos recolectados: 34
tweets_historicos
#> # A tibble: 34 × 6
#>    art_html  fecha               user            tweet url   fecha_captura      
#>    <list>    <dttm>              <chr>           <chr> <chr> <dttm>             
#>  1 <chr [1]> 2018-10-29 23:54:40 @gjmount        "\nC… http… 2024-10-09 10:54:12
#>  2 <chr [1]> 2018-10-29 23:53:10 @ahammami0      "\nP… http… 2024-10-09 10:54:12
#>  3 <chr [1]> 2018-10-29 23:49:06 @ChrisTokita    "\nC… http… 2024-10-09 10:54:12
#>  4 <chr [1]> 2018-10-29 23:35:04 @gp_pulipaka    "\nI… http… 2024-10-09 10:54:12
#>  5 <chr [1]> 2018-10-29 23:30:07 @gp_pulipaka    "\nA… http… 2024-10-09 10:54:12
#>  6 <chr [1]> 2018-10-29 23:28:07 @gp_pulipaka    "\nL… http… 2024-10-09 10:54:12
#>  7 <chr [1]> 2018-10-29 23:26:09 @gp_pulipaka    "\nM… http… 2024-10-09 10:54:12
#>  8 <chr [1]> 2018-10-29 23:00:32 @tidyversetwee… "\nG… http… 2024-10-09 10:54:12
#>  9 <chr [1]> 2018-10-29 23:00:31 @tidyversetwee… "\nW… http… 2024-10-09 10:54:12
#> 10 <chr [1]> 2018-10-29 23:00:26 @ProCogia       "\nW… http… 2024-10-09 10:54:12
#> # ℹ 24 more rows
# Ahora con la getTweetsHistoricalTimeline() recuperamos los datos de tweets originales 
# de la cuenta rstatstweet.

timeline_tweets <- getTweetsHistoricalTimeline(username = "rstatstweet", n_tweets = 10, 
                                               since = "2018-10-26", until = "2020-10-30")
#> Inició la recolección de tweets.
#> Finalizó la recolección de tweets.
#> Procesando datos...
#> Datos procesados y guardados.
#> Tweets únicos recolectados: 13
# Imprimimos en pantalla los datos de los tweets recuperados

timeline_tweets
#> # A tibble: 13 × 6
#>    art_html  fecha               user         tweet    url   fecha_captura      
#>    <list>    <dttm>              <chr>        <chr>    <chr> <dttm>             
#>  1 <chr [1]> 2020-09-25 22:12:32 @rstatstweet "I can’… http… 2024-10-09 10:54:36
#>  2 <chr [1]> 2020-09-24 15:58:14 @rstatstweet "Welcom… http… 2024-10-09 10:54:36
#>  3 <chr [1]> 2020-09-24 15:30:13 @rstatstweet "\nI am… http… 2024-10-09 10:54:36
#>  4 <chr [1]> 2020-09-24 15:10:16 @rstatstweet "This i… http… 2024-10-09 10:54:36
#>  5 <chr [1]> 2020-09-24 15:05:32 @rstatstweet "\nThan… http… 2024-10-09 10:54:36
#>  6 <chr [1]> 2020-09-24 13:07:33 @rstatstweet "\nThan… http… 2024-10-09 10:54:36
#>  7 <chr [1]> 2020-09-24 09:11:22 @rstatstweet "That’s… http… 2024-10-09 10:54:36
#>  8 <chr [1]> 2020-09-24 00:28:46 @rstatstweet "I will… http… 2024-10-09 10:54:36
#>  9 <chr [1]> 2020-09-24 00:25:17 @rstatstweet "\nTher… http… 2024-10-09 10:54:36
#> 10 <chr [1]> 2020-09-24 00:21:15 @rstatstweet "\nSo t… http… 2024-10-09 10:54:36
#> 11 <chr [1]> 2020-09-24 00:16:20 @rstatstweet "I was … http… 2024-10-09 10:54:36
#> 12 <chr [1]> 2020-09-24 00:09:42 @rstatstweet "\nThis… http… 2024-10-09 10:54:36
#> 13 <chr [1]> 2020-02-12 01:36:45 @rstatstweet "Happy … http… 2024-10-09 10:54:36
# Ahora con la función getUsersFullData() recuperamos los datos de usuarixs a 
# partir de las URLs de users recuperadas en el objeto tweets_historicos.

users <- unique(gsub("@", "", tweets_historicos$user))
usuarixs <- getUsersFullData(urls_users = paste0("https://x.com/", users))
#> 
#> Terminando el proceso.
#>       
#> Usuarixs recuperados: 25 
#> Usuarixs no recuperados: 0
# Imprimimos en pantalla los datos de lxs users recuperadxs 

dplyr::glimpse(usuarixs)
#> Rows: 25
#> Columns: 13
#> $ fecha_creacion       <dttm> 2014-05-11 11:32:54, 2017-10-11 08:04:19, 2009-0…
#> $ nombre_adicional     <chr> "gjmount", "ahammami0", "ChrisTokita", "gp_pulipa…
#> $ descripcion          <chr> "I teach analytics in modern Excel 📚 O'Reilly Au…
#> $ nombre               <chr> "George Mount", "Abdessalem Hammami", "Chris Toki…
#> $ ubicacion            <chr> "Cleveland, OH", "Joensuu, Suomi", "Los Angeles, …
#> $ identificador        <chr> "2489702532", "918024449194065925", "41155612", "…
#> $ url_imagen           <chr> "https://pbs.twimg.com/profile_images/16538332253…
#> $ url_miniatura        <chr> "https://pbs.twimg.com/profile_images/16538332253…
#> $ seguidorxs           <int> 4674, 125, 1529, 183257, 12025, 1621, 2351, 396, …
#> $ amigxs               <int> 4273, 120, 1880, 20258, 0, 147, 1919, 310, 2505, …
#> $ tweets               <int> 29713, 883, 5653, 92873, 98491, 1545, 1004, 779, …
#> $ url                  <chr> "https://twitter.com/gjmount", "https://twitter.c…
#> $ enlaces_relacionados <chr> "https://t.co/JcWH7Lwy9r, https://stringfestanaly…

About

Este paquete proporciona funciones para extraer datos de X/Twitter, incluidos tweets, usuarixs y metadatos asociados sin necesidad de usar API. || This package provides functions to extract X/Twitter data, including tweets, usuarixs and associated met

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages