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()
可用於解碼影像並將其儲存為適當的格式。