【问题标题】:how can I change my location while trying to scrape the website?如何在尝试抓取网站时更改我的位置?
【发布时间】:2021-04-15 12:41:33
【问题描述】:

如果访问者不在土耳其,我正在开发一个不显示任何产品的网站。该网站是Carrefoursa。当我尝试用我的电脑进行刮擦时,这没关系,因为我在土耳其的位置。我的服务器位于德国,由于位置原因,蜘蛛无法在服务器上运行。我已经尝试了如下方法:

我尝试使用 Request 发送它

class CarrefoursaSpider(scrapy.Spider):
    name = 'carrefoursa'
    allowed_domains = ['www.carrefoursa.com']
    start_urls = ['https://www.carrefoursa.com/meyve/c/1015']
    custom_settings = {
        "LOG_FILE":"scrapy_logs/"+name+".log",
        "ROBOTSTXT_OBEY":False,
        "USER_AGENTS":None,
        "COOKIES_ENABLED":True,
        "COOKIES_DEBUG" : True
        }
    def parse(self,reponse):
        request = scrapy.Request(
                reponse.url, callback=self.parse_product,cookies={'Content-Language':'tr','currency': 'TRY', 'country': 'TR','lang': 'tr'}, dont_filter=True)
        yield request
        
    def parse_product(self, response):
             ...

我尝试将网站与另一个国家/地区的 VPN 连接,但出现以下错误。

The requested URL was rejected. Please consult with your administrator.

Your support ID is: ******

除了代理,你有什么建议吗?

【问题讨论】:

  • 这称为地理围栏。 Web 服务器正在检查连接到它的客户端的 IP 地址,并将其与位于该国家/地区内的已知 IP 范围列表进行比较。您不能通过更改您的 HTTP 请求来规避这一点。您必须使用代理或 VPN,以便连接来自国内。
  • 好吧,我想我会买一个代理:(你可以写下你的答案我会接受

标签: python web-scraping scrapy web-crawler


【解决方案1】:

我向我的蜘蛛添加了一个元标记,它解决了我的问题。

class CarrefoursaSpider(scrapy.Spider):
    name = 'carrefoursa'
    allowed_domains = ['www.carrefoursa.com']
    start_urls = ['https://www.carrefoursa.com/meyve/c/1015']
    meta={'proxy': 'xxx.xxx.xxx.xx:xxxx'},
    custom_settings = {
        "LOG_FILE":"scrapy_logs/"+name+".log",
        "ROBOTSTXT_OBEY":False,
        "USER_AGENTS":None,
        "COOKIES_ENABLED":True,
        "COOKIES_DEBUG" : True
        }
    def parse(self,reponse):
        request = scrapy.Request(
                reponse.url, callback=self.parse_product,cookies={'Content-Language':'tr','currency': 'TRY', 'country': 'TR','lang': 'tr'}, dont_filter=True)
        yield request
        
    def parse_product(self, response):
             ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-30
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 2021-02-18
    相关资源
    最近更新 更多