2012-12-25 2 views
6

내가 Scrapy 새로운 오전과 내가 뭘하려고 오전에만 예를 들어 내가 그냥 크롤러가 저점을 가고 싶어 말할 수있는 것처럼 주어진 start_urlsScrapy에서 Xpath 내의 링크 만 크롤링하도록하려면 어떻게해야합니까?

에 HTML 요소 내부의 링크를 따라하는 크롤러를 만드는 것입니다 에어 비앤비 목록은 start_urls 어떻게 할 수있는, https://www.airbnb.com/s?location=New+York%2C+NY&checkin=&checkout=&guests=1 대신 난 그냥 XPath는 내가 모든 링크를 크롤링하려면 다음 코드를 사용하고 현재 //*[@id="results"]

내부 링크를 크롤링 할 URL의 모든 링크를 크롤링

로 설정 한 나는 그것을 단지 크롤링하기 위해 적응한다 //*[@id="results"]

from scrapy.selector import HtmlXPathSelector 
    from tutorial.items import DmozItem 
    from scrapy.contrib.spiders import CrawlSpider, Rule 
    from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor 
    from scrapy.selector import HtmlXPathSelector 


    class BSpider(CrawlSpider): 
      name = "bt" 
      #follow = True 
      allowed_domains = ["mydomain.com"] 
      start_urls = ["http://myurl.com/path"] 
      rules =(Rule(SgmlLinkExtractor(allow =()) ,callback = 'parse_item', follow=True),) 


     def parse_item(self, response): 
     {parse code} 

올바른 방향으로 모든 팁은 많이 주시면 감사합니다, 감사합니다!

답변

8

restrict_xpaths 키워드 인수를 SgmlLinkExtractor에 전달할 수 있습니다. the docs에서 :

  • restrict_xpaths (STR 또는 목록) - 링크가 추출되어야하는 응답 내부 영역을 정의하는의 XPath (XPath는 또는의리스트)이다. 주어진 경우 해당 XPath에서 선택한 텍스트 만 링크가 있는지 검사합니다.
+0

감사! 그게 왠지 내가봤을 때 웬일인지 아무 것도 못 찾았어요. 바로 문서로 바로가는 것이 쉽습니다. – JordanBelf

관련 문제