为什么Scrapy会返回Iframe?

时间:2016-09-06 17:13:12

标签: python iframe web-scraping scrapy web-crawler

我想通过Python-Scrapy抓取this site

我试试这个

class Parik(scrapy.Spider):
    name = "ooshop"
    allowed_domains = ["http://www.ooshop.com/courses-en-ligne/Home.aspx"]

    def __init__(self, idcrawl=None, proxy=None, *args, **kwargs):
        super(Parik, self).__init__(*args, **kwargs)
        self.start_urls = ['http://www.ooshop.com/courses-en-ligne/Home.aspx']

    def parse(self, response):
        print response.css('body').extract_first()

但我没有第一页,我有一个空的iframe

2016-09-06 19:09:24 [scrapy] DEBUG: Crawled (200) <GET http://www.ooshop.com/courses-en-ligne/Home.aspx> (referer: None)
<body>
<iframe style="display:none;visibility:hidden;" src="//content.incapsula.com/jsTest.html" id="gaIframe"></iframe>
</body>
2016-09-06 19:09:24 [scrapy] INFO: Closing spider (finished)

1 个答案:

答案 0 :(得分:2)

该网站受网站安全服务公司Incapsula的保护。它提供了您的浏览器&#34;在获得允许您访问网站本身的特殊cookie之前必须执行的挑战。

幸运的是,它并没有那么难以绕过。安装incapsula-cracker并安装其下载中间件:

DOWNLOADER_MIDDLEWARES = {
    'incapsula.IncapsulaMiddleware': 900
}