代理位置
了解如何使用 geo_location 参数以仿佛从不同国家浏览的方式访问网页数据。
使用 geo_location 参数选择代理服务器的位置。这样你可以像从另一个国家浏览一样抓取数据。
请求示例
此示例使用位于德国的代理检索产品页面。
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
"source": "universal",
"url": "https://sandbox.oxylabs.io/products/1",
"geo_location": "Germany"
}'import requests
from pprint import pprint
# 构建负载。
payload = {
'source': 'universal',
'url': 'https://sandbox.oxylabs.io/products/1',
'geo_location': 'Germany',
}
# 获取响应。
response = requests.request(
'POST',
'https://realtime.oxylabs.io/v1/queries',
auth=('USERNAME', 'PASSWORD'),
json=payload,
)
# 该请求不会返回带有作业状态和结果 URL 的响应,而是返回
# 包含结果的 JSON 响应。
pprint(response.json())我们在示例中使用同步 Realtime 集成方法。如果您想使用 Proxy Endpoint 或异步 Push-Pull 集成,请参阅 集成方法 部分。
会话
你可以通过包含 session_id 参数来强制对多个请求使用相同的代理 IP。将会话 ID 设置为任意字母数字字符串(例如, abc123),具有该会话 ID 的所有抓取任务都将使用相同的 IP。当与 自定义 Cookie.
结合使用时,这对会话管理很有用。
最后更新于
这有帮助吗?

