python - 使用 scrapy 进行网页抓取论坛不会产​​生下一页

标签 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 脚本中执行该蜘蛛时,通常(我的意思是对于其他论坛)它会从起始 URL 开始抓取所有页面的所有线程。

但对于那个,它不会,它只废弃第一页的所有线程,它获取进入第二页的正确 URL,但会再次调用解析函数。

当然,如果我将所有页面的 URL 放入 start_urls 列表中,它会废弃所有页面...

感谢您的帮助。

最佳答案

您收到的 HTTP 429 响应意味着该网站正在限制您的请求以避免被淹没。您可以使用the AutoThrottle extension将您的请求频率限制在网站允许的范围内。

关于python - 使用 scrapy 进行网页抓取论坛不会产​​生下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51264283/

相关文章:

python - 使用scrapy,python中的站点地图蜘蛛解析站点地图中具有不同url格式的url

linux - 如何在 Linux 中将 Scrapy 的屏幕输出存储到文件中

php - 我怎么知道谷歌蜘蛛或其他蜘蛛是否访问了我的页面?

python - 在不破坏管道的情况下与进程多次通信?

python - Windows7 本地主机上的 Selenium Remote Webdriver 抛出空指针异常

Python Webscrape 通过 Scrapy 或 Excel 查询搜索?

screen-scraping - Mozenda Screen Scraper 是如何编码的?

java - 比正则表达式更好的系统

python - 如何让 OpenCV 在 Raspberry Pi 4 (Raspbian Buster) 上完全运行?

python - 替换 Python 2.7 中的打印语句