这是我正在抓取的网站。起初我没有问题,但后来我遇到了这个错误。
[scrapy] DEBUG: Redirecting (meta refresh) to <GET https://www.propertyguru.com.my/distil_r_captcha.html?requestId=9f8ba25c-3673-40d3-bfe2-6e01460be915&httpReferrer=%2Fproperty-for-rent%2F1> from <GET https://www.propertyguru.com.my/property-for-rent/1>
网站知道我是机器人并将我重定向到带有验证码的页面。我认为handle_httpstatus_list
ordont_redirect
不起作用,因为重定向不是使用 http 状态代码完成的。这是我的爬虫代码。有没有办法阻止这种重定向?
class MySpider(CrawlSpider):
name = 'myspider'
start_urls = [
'https://www.propertyguru.com.my/property-for-rent/1',
]
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
meta = {
'dont_redirect': True
}
def parse(self, response):
items = response.css('div.header-container h3.ellipsis a.nav-link::attr(href)').getall()
if items:
for item in items:
if item.startswith('/property-listing/'):
yield scrapy.Request(
url='https://www.propertyguru.com.my{}'.format(item),
method='GET',
headers=self.headers,
meta=self.meta,
callback=self.parse_items
)
def parse_items(self, response):
from scrapy.shell import inspect_response
inspect_response(response, self)
更新:我尝试了这些设置,但它们也不起作用。
custom_settings = {
'DOWNLOAD_DELAY': 5,
'DOWNLOAD_TIMEOUT': 360,
'CONCURRENT_REQUESTS_PER_DOMAIN': 1,
'CONCURRENT_ITEMS': 1,
'REDIRECT_MAX_METAREFRESH_DELAY': 200,
'REDIRECT_MAX_TIMES': 40,
}