2017-12-05 11 views
1

나는 scrapy를 처음 사용하고 있는데 왜 내가 scrap shell에서 필요로하는 요소를 추출 할 수 있었는지 알아보기 위해 시도했지만 커맨드 라인에서 생성 한 scream 거미는 추출 할 수 없었다. 다음 반환scrapy shell보다 scrapy spider에서 다른 출력

pipenv run scrapy shell http://quotes.toscrape.com/ 

그런

response.css('small.author::text').extract() 

:이 모든 의도로

['Albert Einstein', 'J.K. Rowling', 'Albert Einstein', 'Jane Austen', 'Marilyn Monroe', 'Albert Einstein', 'André Gide', 'Thomas A. Edison', 'Eleanor Roosevelt', 'Steve Martin']

scrapy 쉘에서

나는 다음을했다. 그러나 나는 거미 거미를 만들고 나중에 실행할 때 몇 가지 문제가 있기 시작합니다. 내 코드는 다음과 같습니다 : 나는 내가 느낌을 얻을

2017-12-04 20:03:56 [yolo1] DEBUG: Just visitedhttp://www.dnsrsearch.com/index.php?origURL= http://http/quotes.toscrape.com/&bc= 2017-12-04 20:03:56 [scrapy.core.scraper] ERROR: Error processing {'author': []} Traceback (most recent call last): File "c:\users\alice.virtualenvs\all-the-places-c44chfla\lib\site-packages\twisted\internet\defer.py", line 653, in _runCallbacks current.result = callback(current.result, *args, **kw) File "C:\Users\alice\all-the-places\locations\pipelines.py", line 16, in process_item ref = item['ref'] KeyError: 'ref'

다음과 같이 내가 얻을 수 있습니다

pipenv run scrapy crawl yolo1 

오류 :

# -*- coding: utf-8 -*- 
import scrapy 

class Yolo1Spider(scrapy.Spider): 
    name = 'yolo1' 
    allowed_domains = ['toscrape.com'] 
    start_urls = ['http://http://quotes.toscrape.com/'] 

    def parse(self, response): 
     self.log('Just visited' + response.url) 
     yield { 
      'author': response.css('small.author::text').extract() 
      } 

내가 명령 행에서 거미를 실행 그냥 간단한 것을 놓치고 있지만 내 인생에서 나는 그것을 알아낼 수 없으며 장소 곳곳에서 확인하고 있습니다.

스파이더 크롤링의 출력에서 ​​내가 작성한 디버그 라인이 인쇄되었지만 그 후에 오류가 발생하는 것을 볼 수 있습니다. 정말 내가했던 스파이더와 커맨드 라인에서 동일한 출력을 얻어야한다고 생각했습니다.

+0

당신이 http://http://quotes.toscrape.com/를 참조'에 http : // '두 번 URL에 -'참조 '에 http : // HTTP : // quotes.toscrape.com /' – furas

답변

0

시작 URL에 실수로 - http://을 두 번 잘못 입력했습니다.

+1

정말 감사합니다. 때로는 이런 것들에 대한 새로운 시각이 필요합니다. –