Scrapy爬虫不能使用网站我得到部分结果

时间:2016-08-21 18:34:27

标签: python scrapy web-crawler partial

我是Scrapy和Python的新手。我一直在努力从2个网站中提取数据,如果我直接使用python,它们的效果非常好。我已调查过,我想抓取这些网站:

  1. homedepot.com.mx/comprar/es/miguel-aleman/home(完美运作)
  2. vallenproveedora.com.mx/(不起作用)
  3. 有人可以告诉我如何才能使第二个链接起作用?

    我看到了这条消息:

    DEBUG: Crawled (200) allenproveedora.com.mx/> (referer: None) ['partial']
    

    但我无法找到解决方法。

    我将不胜感激任何帮助和支持。这是代码和日志:

    items.py
    
    from scrapy.item import Item, Field
    
    class CraigslistSampleItem(Item):
        title = Field()
        link = Field()
    

    Test.py(蜘蛛文件夹)

    from scrapy.spider import BaseSpider
    from scrapy.selector import HtmlXPathSelector
    from craigslist_sample.items import CraigslistSampleItem
    
    class MySpider(BaseSpider):
        name = "craig"
        allowed_domains = ["vallenproveedora.com.mx"]
        #start_urls = ["http://www.homedepot.com.mx/webapp/wcs/stores/servlet/SearchDisplay?searchTermScope=&filterTerm=&orderBy=&maxPrice=&showResultsPage=true&langId=-5&beginIndex=0&sType=SimpleSearch&pageSize=&manufacturer=&resultCatEntryType=2&catalogId=10052&pageView=table&minPrice=&urlLangId=-5&storeId=13344&searchTerm=guante"]
        start_urls = ["http://www.vallenproveedora.com.mx/"]
        def parse(self, response):
            titles = response.xpath('//ul/li')
            for titles in titles:
                title = titles.select("a/text()").extract()
                link = titles.select("a/@href").extract()
                print (title, link)
    

1 个答案:

答案 0 :(得分:1)

您在日志中看到['partial'],因为vallenproveedora.com.mx上的服务器未在其响应中设置Content-Length标头;运行curl -I来亲眼看看。有关partial标记原因的详细信息,请参阅my answer here

但是,您实际上不必担心这一点。响应主体就在那里,Scrapy将解析它。您遇到的问题是XPath //ul/li/a没有选择任何元素。您应该查看页面源并相应地修改选择器。我建议为每个站点编写一个特定的蜘蛛,因为站点通常需要不同的选择器。