在抓取网页时,我怎么能假装在某个国家?

2024-05-15 04:33:02 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

用户代理是我需要的。但我能不能把这个和我在某个国家的要求结合起来?在

如果有一些可能性(在scrpy,Python)请告诉我。谢谢!在

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

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

Tags: 用户httpsorgprojectpypi示例代理网站
3条回答

您可以使用Selenium(不知道Scrapy),首先告诉bot转到这个siteProxy Site

然后将你的目标站点添加到搜索框中并进行刮取。在

为了伪装某个国家,你需要那个国家的知识产权。不幸的是,这不是你可以通过垃圾设置等来配置的,但是你可以使用像crawlera这样的代理服务:

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

注:不幸的是,这项服务不是免费的,最便宜的套餐大约是25欧元。还有许多其他更便宜的服务。Crawlera之所以昂贵,是因为它们提供了ban检测,并且只为您选择的域提供好的ip。我发现它们对亚马逊和谷歌的成本很有用。虽然在较小的域上,更便宜的服务和无限的服务将更适合。在

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..

相关问题 更多 >

    热门问题