https://github.com/agusnieto77/tweetscraperr
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
https://github.com/agusnieto77/tweetscraperr
scraper scraping tweets twitter
Last synced: about 1 month ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/agusnieto77/tweetscraperr
- Owner: agusnieto77
- License: mit
- Created: 2024-05-11T02:08:24.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-16T17:38:09.000Z (about 1 year ago)
- Last Synced: 2026-02-16T10:55:12.326Z (5 months ago)
- Topics: scraper, scraping, tweets, twitter
- Language: R
- Homepage:
- Size: 50.8 MB
- Stars: 29
- Watchers: 6
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TweetScraperR
[](https://www.repostatus.org/#active)
[](https://github.com/agusnieto77/TweetScraperR)
[](https://cran.r-project.org/web/licenses/MIT)
[](https://github.com/agusnieto77/TweetScraperR)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/agusnieto77/TweetScraperR)
[](https://github.com/agusnieto77/TweetScraperR)
### 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](https://github.com/) con:
``` r
# 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. |
| `getTweetsCites()` |  | Recupera las citas de un tweet a partir de su URL. |
| `getTweetsData()` |  | Recupera datos de tweets a partir de URLs. |
| `getTweetsData2()` |  | 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. |
| `getTweetsReplies()` |  | Recupera las respuesta a un tweet desde su URL. |
| `getTweetsRetweets()` |  | Recupera los usuarios que rt un tweet desde su URL. |
| `getTweetsSearchStreaming()` |  | Recupera tweets en tiempo real. |
| `getTweetsSearchStreaming2()` |  | Recupera tweets en tiempo real. |
| `getTweetsSearchStreamingFor()` |  | Itera la recuperación de tweets en tiempo real. |
| `getTweetsSearchStreamingFor2()` |  | 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. |
| `getUrlsTweetsCites()` |  | Recupera las URLs de las citas de un tweet. |
| `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. |
| `passTwitter()` |  | Función de login, completa el campo pass. |
| `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'. |
| `userTwitter()` |  | Función de login, completa el campo user. |
### Uso de las funciones del paquete {TweetScraperR}
``` r
# 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
``` r
urls_hashtagRstats
```
#> # A tibble: 8 × 6
#> art_html fecha user tweet url fecha_captura
#>
#> 1 2024-10-09 13:39:56 @BiochemistTomas "\nW… http… 2024-10-09 10:53:25
#> 2 2024-10-09 13:22:23 @RodgersData "\nA… http… 2024-10-09 10:53:25
#> 3 2024-10-09 12:17:43 @rcityviews "\nI… http… 2024-10-09 10:53:25
#> 4 2024-10-09 12:16:37 @d_mykhailyshyna "\nT… http… 2024-10-09 10:53:25
#> 5 2024-10-09 12:04:54 @cyberpuck01 "\nC… http… 2024-10-09 10:53:25
#> 6 2024-10-09 11:59:31 @leonardohansa "\nD… http… 2024-10-09 10:53:25
#> 7 2024-10-09 11:58:01 @BjnNowak "\nT… http… 2024-10-09 10:53:25
#> 8 2024-10-09 11:57:34 @HackCyber80 "\nC… http… 2024-10-09 10:53:25
``` r
# 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
``` r
tweets_historicos
```
#> # A tibble: 34 × 6
#> art_html fecha user tweet url fecha_captura
#>
#> 1 2018-10-29 23:54:40 @gjmount "\nC… http… 2024-10-09 10:54:12
#> 2 2018-10-29 23:53:10 @ahammami0 "\nP… http… 2024-10-09 10:54:12
#> 3 2018-10-29 23:49:06 @ChrisTokita "\nC… http… 2024-10-09 10:54:12
#> 4 2018-10-29 23:35:04 @gp_pulipaka "\nI… http… 2024-10-09 10:54:12
#> 5 2018-10-29 23:30:07 @gp_pulipaka "\nA… http… 2024-10-09 10:54:12
#> 6 2018-10-29 23:28:07 @gp_pulipaka "\nL… http… 2024-10-09 10:54:12
#> 7 2018-10-29 23:26:09 @gp_pulipaka "\nM… http… 2024-10-09 10:54:12
#> 8 2018-10-29 23:00:32 @tidyversetwee… "\nG… http… 2024-10-09 10:54:12
#> 9 2018-10-29 23:00:31 @tidyversetwee… "\nW… http… 2024-10-09 10:54:12
#> 10 2018-10-29 23:00:26 @ProCogia "\nW… http… 2024-10-09 10:54:12
#> # ℹ 24 more rows
``` r
# 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
``` r
# Imprimimos en pantalla los datos de los tweets recuperados
timeline_tweets
```
#> # A tibble: 13 × 6
#> art_html fecha user tweet url fecha_captura
#>
#> 1 2020-09-25 22:12:32 @rstatstweet "I can’… http… 2024-10-09 10:54:36
#> 2 2020-09-24 15:58:14 @rstatstweet "Welcom… http… 2024-10-09 10:54:36
#> 3 2020-09-24 15:30:13 @rstatstweet "\nI am… http… 2024-10-09 10:54:36
#> 4 2020-09-24 15:10:16 @rstatstweet "This i… http… 2024-10-09 10:54:36
#> 5 2020-09-24 15:05:32 @rstatstweet "\nThan… http… 2024-10-09 10:54:36
#> 6 2020-09-24 13:07:33 @rstatstweet "\nThan… http… 2024-10-09 10:54:36
#> 7 2020-09-24 09:11:22 @rstatstweet "That’s… http… 2024-10-09 10:54:36
#> 8 2020-09-24 00:28:46 @rstatstweet "I will… http… 2024-10-09 10:54:36
#> 9 2020-09-24 00:25:17 @rstatstweet "\nTher… http… 2024-10-09 10:54:36
#> 10 2020-09-24 00:21:15 @rstatstweet "\nSo t… http… 2024-10-09 10:54:36
#> 11 2020-09-24 00:16:20 @rstatstweet "I was … http… 2024-10-09 10:54:36
#> 12 2020-09-24 00:09:42 @rstatstweet "\nThis… http… 2024-10-09 10:54:36
#> 13 2020-02-12 01:36:45 @rstatstweet "Happy … http… 2024-10-09 10:54:36
``` r
# 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
``` r
# Imprimimos en pantalla los datos de lxs users recuperadxs
dplyr::glimpse(usuarixs)
```
#> Rows: 25
#> Columns: 13
#> $ fecha_creacion 2014-05-11 11:32:54, 2017-10-11 08:04:19, 2009-0…
#> $ nombre_adicional "gjmount", "ahammami0", "ChrisTokita", "gp_pulipa…
#> $ descripcion "I teach analytics in modern Excel 📚 O'Reilly Au…
#> $ nombre "George Mount", "Abdessalem Hammami", "Chris Toki…
#> $ ubicacion "Cleveland, OH", "Joensuu, Suomi", "Los Angeles, …
#> $ identificador "2489702532", "918024449194065925", "41155612", "…
#> $ url_imagen "https://pbs.twimg.com/profile_images/16538332253…
#> $ url_miniatura "https://pbs.twimg.com/profile_images/16538332253…
#> $ seguidorxs 4674, 125, 1529, 183257, 12025, 1621, 2351, 396, …
#> $ amigxs 4273, 120, 1880, 20258, 0, 147, 1919, 310, 2505, …
#> $ tweets 29713, 883, 5653, 92873, 98491, 1545, 1004, 779, …
#> $ url "https://twitter.com/gjmount", "https://twitter.c…
#> $ enlaces_relacionados "https://t.co/JcWH7Lwy9r, https://stringfestanaly…