Try to search your question here, if you can't find : Ask Any Question Now ?

Scrapy Spider doesn't scrape anything

HomeCategory: stackoverflowScrapy Spider doesn't scrape anything
Avatarcraig asked 1 month ago

I am trying to scrape this web-site https://www.bhp.com/media-and-insights/reports-and-presentations?q0_r=category%3dAnnual%2bReports howerver the spider does not return any loaded items. What am I missing?

I tested the xpaths with scrapy shell and they seem to be working just fine.

SPIDER:

import scrapy
from third_stage.items import ThirdStageItem
from scrapy.loader import ItemLoader
from scrapy.loader.processors import MapCompose
from urllib.parse import urljoin


class BhpSpider(scrapy.Spider):
    name = 'bhp'
    allowed_domains = ['web']
    start_urls = ['https://www.bhp.com/media-and-insights/reports-and- 
                  presentations?q0_r=category%3dAnnual%2bReports/',]

    def parse(self, response):
        i = ItemLoader(item=ThirdStageItem(), response=response)
        i.add_xpath('title', '//h2/a/text()')
        i.add_xpath('description', '//*[@class="col-9"]/p/text()')
        i.add_xpath('info_url', '//h2/a/@href', MapCompose(lambda i: 
                    urljoin(response.url, i)))
        return i.load_item()

ITEMS:

import scrapy
from scrapy.item import Item
from scrapy.item import Field

class ThirdStageItem(Item):
    title = Field()
    description = Field()
    info_url = Field()
    pass

SETTINGS:

BOT_NAME = 'third_stage'
SPIDER_MODULES = ['third_stage.spiders']
NEWSPIDER_MODULE = 'third_stage.spiders'
ROBOTSTXT_OBEY = False

OUTPUT:

2019-07-14 16:53:34 [scrapy.core.engine] INFO: Spider opened
2019-07-14 16:53:34 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2019-07-14 16:53:34 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6024
2019-07-14 16:53:34 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.bhp.com/media-and-insights/reports-and-presentations?q0_r=category%3dAnnual%2bReports/> (referer: None)
2019-07-14 16:53:34 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.bhp.com/media-and-insights/reports-and-presentations?q0_r=category%3dAnnual%2bReports/>
{}
2019-07-14 16:53:34 [scrapy.core.engine] INFO: Closing spider (finished)
2019-07-14 16:53:34 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 288,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 6601,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2019, 7, 14, 14, 53, 34, 791840),
 'item_scraped_count': 1,
 'log_count/DEBUG': 3,
 'log_count/INFO': 7,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2019, 7, 14, 14, 53, 34, 528793)}
2019-07-14 16:53:34 [scrapy.core.engine] INFO: Spider closed (finished)
1 Answers
Best Answer
AvatarMatthias answered 1 month ago
Your Answer

0 + 6 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com