webbotparseR
1.0.0
webbotparseR 允许解析使用 WebBot 浏览器扩展抓取的搜索引擎结果。类似的 python 库也可用。
您可以像这样安装 webbotparseR 的开发版本:
remotes :: install_github( " schochastics/webbotparseR " )
该包包含来自谷歌气候变化搜索的示例 html。
library( webbotparseR )
ex_file <- system.file( " www.google.com_climatechange_text_2023-03-16_08_16_11.html " , package = " webbotparseR " )
此类搜索结果可以通过函数parse_search_results()
进行解析。参数engine
用于指定搜索引擎和搜索类型。
output <- parse_search_results( path = ex_file , engine = " google text " )
output
# > # A tibble: 10 × 10
# > title link text image page position search_engine type query
# > <chr> <chr> <chr> <chr> <chr> <int> <chr> <chr> <chr>
# > 1 What Is Climate C… http… Clim… data… 1 1 www.google.c… text clim…
# > 2 Home – Climate Ch… http… Vita… data… 1 2 www.google.c… text clim…
# > 3 Vital Signs of th… http… “Cli… data… 1 3 www.google.c… text clim…
# > 4 Climate change - … http… In c… data… 1 4 www.google.c… text clim…
# > 5 IPCC — Intergover… http… The … data… 1 5 www.google.c… text clim…
# > 6 Climate Change | … http… Comp… data… 1 6 www.google.c… text clim…
# > 7 Climate change: e… http… Clim… <NA> 1 7 www.google.c… text clim…
# > 8 UNFCCC http… What… data… 1 8 www.google.c… text clim…
# > 9 Climate Change - … http… Clim… data… 1 9 www.google.c… text clim…
# > 10 Causes of climate… http… This… data… 1 10 www.google.c… text clim…
# > # ℹ 1 more variable: date <dttm>
请注意,图像始终以 Base64 编码返回。
output $ image [ 1 ]
# > [1] "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAAMklEQVR4AWMAgYYG4hEdNJAHGoCIABvBJayhgcYaIAwaakCwydUA52MKYeeSCgZh4gMAXrJ9ASggqqAAAAAASUVORK5CYII="
函数base64_to_img()
可用于解码图像并将其保存为适当的格式。