如何在 R 中将 Zyte 与 HTTR 结合使用

问题描述 投票:0回答:1

我需要使用轮换代理 IP 服务,并选择使用 Zyte,因为这是我们在前公司使用的服务。我在 R 中使用 Zyte API 时遇到了麻烦。我已经弄乱了三四个小时,似乎无法找到如何输入所有 API 端点、目标 url 和 api_key 信息。我更喜欢使用 httr,但如果更容易的话,我会很乐意使用curl 或 RCurl。

这是来自互联网和 ChatGPT 的帮助的大杂烩:

library(httr)
library(jsonlite)

api_url <- "http://proxy.zyte.com:8011/api/v2/"
api_key <- "API_KEY"
target_url <- all_links.vec[100]
response <- GET(url = api_url,
                add_headers(`Proxy-Authorization` = paste('Basic', base64_enc(api_key)),
                            `targeturl` = target_url))

我能做到的最接近的是不小心抓取了 Zyte 的网站。

有人可以帮我让它工作吗? Zyte 文档链接: Zyte 文档 我已为 Zyte API 付费,而不是智能代理管理器。

我应该指出,我完全愿意使用不同的服务,但我相当愿意使用 R。我正处于 Zyte 试用阶段的第一天,所以摆脱它没有什么坏处,但我已经一年了使用 R 的 10 次,所以对我来说使用它比切换到 Python 容易得多。

r proxy httr rcurl zyte
1个回答
0
投票

根据我在帮助文档中看到的少量信息,我想知道this是否可能更有用:


curl \
    --proxy https://api.zyte.com:8014 \
    --proxy-user YOUR_API_KEY: \
    --compressed \
    https://toscrape.com

所以在 R 中它更像是:


httr::GET("whatever_url_to_scrape.com", 
    httr::use_proxy(url = "api.zyte.com", port = 8011, username = "API_KEY")
)

或者可能是
POST
user
设置如文档中所示

?httr::authenticate
不要认为这是一个答案,但评论的信息太多了。祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.