带有刮forum的Web刮forum论坛不会产​​生下一页

时间:2018-07-10 11:41:41

标签: python scrapy web-crawler

为了清楚起见,我尝试爬网有关赌场的论坛,目前,我已成功使用以下相同方案进行了此操作:

class test_spider(scrapy.Spider):
count=0

name = "test_spyder"

start_urls = [

       'https://casinogrounds.com/forum/search/?&q=Casino&search_and_or=or&sortby=relevancy',

]

rules = ( Rule(LinkExtractor(restrict_css=('a:contains("Next")::attr(href)')), callback='parse') )


def parse(self, response) :
    print(self.count)
    for href in response.css("span.ipsType_break.ipsContained a::attr(href)") :
        new_url = response.urljoin(href.extract())
        #print(new_url)
        yield scrapy.Request(new_url, callback = self.parse_review)


    next_page = response.css('a:contains("Next")::attr(href)').extract_first()
    print(next_page)
    if next_page is not None:
        yield scrapy.Request(next_page, callback = self.parse)

def parse_review(self, response):

    parsed_uri = urlparse(response.url)
    domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
    for review in response.css('article.cPost.ipsBox.ipsComment.ipsComment_parent.ipsClearfix.ipsClear.ipsColumns.ipsColumns_noSpacing.ipsColumns_collapsePhone') :

        yield {
            'name': review.css('strong a.ipsType_break::text').extract_first(),
            'date': review.css('time::attr(title)').extract_first(),
            'review': review.css('p::text').extract(),
            'url' : response.url
        }


    next_page = response.css('li.ipsPagination_next a::attr(href)').extract_first()
    if next_page is not None:
        yield response.follow(next_page, callback=self.parse_review)

因此,当我在python脚本中执行该Spider时,通常(对于其他论坛来说)是它从起始URL抓取所有页面的所有线程。

但是对于那个不是,它只刮掉第一页的所有线程,它获得了进入第二页的正确URL,但是又调用了parse函数。

当然,如果我将所有页面的URL都放在start_urls列表中,则会抓取所有页面...

谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您收到的HTTP 429响应表示该网站正在限制您的请求,以避免不知所措。您可以使用the AutoThrottle extension将请求的频率限制为网站允许的范围。