如何在网络抓取期间假装在某个国家/地区?

How can I pretend to be in a certain country during web scraping?

我想抓取一个网站,但它应该看起来像我来自特定的国家(在本例中假设是美国)(以确保我的结果有效)。

我在 Python (Scrapy) 工作。对于抓取,我正在使用轮换用户代理(参见:https://pypi.org/project/scrapy-fake-useragent-fix/)。

用户代理是我需要抓取的内容。但是我可以使用这个,结合假装我在特定国家的请求吗?

如果有一些可能性(在 scrapy 中,Python)请告诉我。赞赏!

示例我如何在我的脚本中使用用户代理

DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 400,
}

要冒充某个国家/地区,您需要该国家/地区的 IP。不幸的是,这不是你可以通过 scrapy 设置等配置的。但是你可以使用像 crawlera 这样的代理服务:

https://support.scrapinghub.com/support/solutions/articles/22000188398-restricting-crawlera-ips-to-a-specific-region

注意:不幸的是,这项服务不是免费的,最便宜的计划约为 25 欧元。还有许多其他更便宜的服务可用。 Crawlera 之所以昂贵,是因为它们提供禁令检测,并且只为您选择的域提供良好的 IP。我发现它们对亚马逊和 Google 的成本很有用。虽然在较小的域上,具有无限服务的更便宜的服务会更合适。

你可以使用 Selenium 来做到这一点(不知道 Scrapy),首先告诉机器人去这个 siteProxy Site

然后将您的目标网站添加到搜索框并抓取。

Hello @helloworld1990,

Based on your requirement, say if you want to make each request using different IPs i.e. use IP Rotation (used when the site is detecting and blocking you after certain requests) then go for "Proxy Providers" there are many such providers you just need to google them.

If its not the case above, then for short term use you can try using TOR IPs. But TOR IPs are well known and are generally blocked. Else, you can still buy few static IPs from Proxy Providers and make the requests.

if(uniqueIpForEachRequestFromDifferentGeoLocations){
//go for proxy providers - IP Rotation
}else{
if(shortTermUse){
//go for tor nodes
}else{
//go for static IPs`enter code here`
}
}

Cheers! Hope this helps..