2016-11-30 1 views
2

임 생각 나는 분야에서 모든 우편 번호 또는 임의의 숫자 입력이 가격 숨겨진 텍스트를 표시하기 위해 Scrapy 를 사용 this 페이지 구문 분석하려고 : 들어Scrapy FormRequest.from_response() 메소드

<input aria-label="Enter your zip code" role="textbox" name="searchTerm" class="form-control js-list-zip-entry-input" placeholder="ZIP Code" autocompletetype="find-a-store-search" tabindex="-1" type="text"> 

을 응답 URL 가격 yse FormRequest.from_response을 시도했지만 성공적이지 않습니다. 어쩌면 누군가가 가격에 어떻게 대응할 수 있는지 설명 할 수 있습니까? 여기서 문제

import scrapy 
from scrapy.http.request import Request 
from scrapy.http import FormRequest 
from scrapy.spiders import CrawlSpider, Rule 
from scrapy.linkextractors import LinkExtractor 

class SattySpider(scrapy.Spider): 
    name = "lowes-faucet" 
    allowed_domains = ["lowes.com"] 
    start_urls = [ "http://www.lowes.com/search?searchTerm=faucets"] 

    def parse(self, response): 
     yield FormRequest.from_response(response, 
              formnumber=1, 
              formxpath='id("store-locator-form")', 
              formdata={'searchTerm': '58000'}, 
              callback=self.parse1, method="GET") 
    def parse(self, response): 
     open_in_browser(response) 
     ... 
+0

parse1은 무엇을합니까? – daniboy000

답변

0

양식이 실제 요청을 보내기 전에 약간의 자바 스크립트 코드를 실행하고, 요청이 다른 사이트로 진행되고 있다는 것입니다, this one for example은 (당신이 실제로 사용하는 어떤 매개 변수를 확인해야합니다) . 그러나 물론, 대부분 쿠키가 더 많은 것들을 전달합니다.

해당 요청을 수행 한 후 서버는 현재 세션이 해당 위치에 있음을 알고 있으므로 실제 데이터로 정보를 얻으려면 이전 사이트에 대해 다른 요청을해야합니다.

  • 요청 쿠키 이전 링크 요청
  • http://www.lowes.com/search?searchTerm=faucets에 :

    Scrapy에서이 같은 일 것입니다. 모든 쿠키

  • 을 통과 http://www.lowes.com/search?searchTerm=faucets에 다시
  • 요청

Scrapy가 자체적으로 쿠키를 처리해야하지만, 물론 100 % 확신 할 수 없다, 일부 사용자 지정 쿠키있을 수 있습니다.