Scrapy Spider를 사용하는 Craigslist Scraper가 기능을 수행하지 않음 (Craigslist Scraper using Scrapy Spider not performing functions)


문제 설명

Scrapy Spider를 사용하는 Craigslist Scraper가 기능을 수행하지 않음 (Craigslist Scraper using Scrapy Spider not performing functions)

2021‑05‑07 10:07:14 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://tampa.craigslist.org/robots.txt> (referer: None)
2021‑05‑07 10:07:14 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://tampa.craigslist.org/d/cell‑phones/search/moa/> (referer: None)
2021‑05‑07 10:07:19 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://tampa.craigslist.org/d/cell‑phones/search/moa?s=120> (referer: https://tampa.craigslist.org/d/cell‑phones/search/moa/)
2021‑05‑07 10:07:21 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://tampa.craigslist.org/d/cell‑phones/search/moa?s=240> (referer: https://tampa.craigslist.org/d/cell‑phones/search/moa?s=120)

이것은 내가 얻은 출력입니다. 다음 버튼을 선택하고 27행에서 요청을 수행하여 수행되는 결과 페이지로 이동하는 것처럼 보입니다.

import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import Rule, Request
from craig.items import CraigItem
from scrapy.selector import Selector


class PhonesSpider(scrapy.Spider):
    name = 'phones'
    allowed_domains = ['tampa.craigslist.org']
    start_urls = ['https://tampa.craigslist.org/d/cell‑phones/search/moa/']



    def parse(self, response):
        phones = response.xpath('//p[@class="result‑info"]')
        for phone in phones:
            relative_url = phone.xpath('a/@href').extract_first()
            absolute_url = response.urljoin(relative_url)
            title = phone.xpath('a/text()').extract_first()
            price = phone.xpath('//*[@id="sortable‑results"]/ul/li[3]/a/span').extract_first()
            yield Request(absolute_url, callback=self.parse_item, meta={'URL': absolute_url, 'Title': title, 'price': price})


        relative_next_url = response.xpath('//a[@class="button next"]/@href').extract_first()
        absolute_next_url = "https://tampa.craigslist.org" + relative_next_url
        yield Request(absolute_next_url, callback=self.parse)



    def parse_item(self, response):
        item = CraigItem()
        item["cl_id"] = response.meta.get('Title')
        item["price"] = response.meta.get
        absolute_url = response.meta.get('URL')

        yield{'URL': absolute_url, 'Title': title, 'price': price}


내 코드에서와 같이 전화 루프의 전화가 실행되지 않아 parse_item을 실행하지 않고 다음 URL을 계속 요청하고 있습니다. 일부 자습서를 따르고 문서를 읽고 있지만 여전히 내가 뭘 잘못하고 있는지 파악하는 데 문제가 있습니다. 어렸을 때 취미로 arduinos를 코딩한 경험이 있지만 전문적인 코딩 경험이 없습니다. 이것이 이와 같은 프로젝트에 대한 저의 첫 번째 장점입니다. 루프, 함수, 콜백 등의 기본 사항은 충분히 이해하고 있습니다.

도움을 주시면 감사하겠습니다.

업데이트

현재 출력


참조 솔루션

방법 1:

Class result‑info is used within the div block, so you should write:

phones = response.xpath('//div[@class="result‑info"]')

That being said, I didn't check/fix your spider further (it seems there are only parsing errors, not functional ones). As a suggestion for the future, you can use Scrapy shell for quickly debugging the issues:

scrapy shell "your‑url‑here"

(by fnctrloptcmdSerhii Shynkarenko)

참조 문서

  1. Craigslist Scraper using Scrapy Spider not performing functions (CC BY‑SA 2.5/3.0/4.0)

#web-crawler #Python #scrapy #web-scraping






관련 질문

UnicodeError: URL에 ASCII가 아닌 문자가 포함되어 있습니다(Python 2.7). (UnicodeError: URL contains non-ASCII characters (Python 2.7))

크롤링 출력 - 두 변수 연결 (Crawling output - connecting two variables)

Python2.7에서 효과적인 크롤러를 만드는 방법 (How to make an effective crawler in Python2.7)

이 텍스트가 다른 기사의 일부임을 Google에 알리는 방법 (How to tell google this text is part of another article)

크롤링하는 HTML 페이지에서 JavaScript 개체를 구문 분석하는 방법은 무엇입니까? (How to parse a JavaScript object from a HTML page I crawl?)

데이터 크롤링 또는 API 사용 (Crawling data or using API)

파이썬을 사용하여 웹사이트에서 내부 링크만 크롤링 (Crawl only internal links from a website using python)

받은 응답에서 HTML 코드를 긁는 방법은 무엇입니까? (How to scrape the html code from the response received?)

PHP를 사용하여 웹 사이트에서 클래스 이름 스크래핑 (Scraping class name on a website using php)

Scrapy Spider를 사용하는 Craigslist Scraper가 기능을 수행하지 않음 (Craigslist Scraper using Scrapy Spider not performing functions)

BeautifulSoup: 이 링크에서 모든 기사 링크를 가져오는 방법은 무엇입니까? (BeautifulSoup: how to get all article links from this link?)

나는 클라이언트입니다. 선택적으로 http 응답에서 헤더를 제거할 수 있습니까? (I'm client. Can I remove header from http response optionally?)







코멘트