【问题标题】:Scrapy Post data to URLScrapy 将数据发布到 URL
【发布时间】:2017-03-19 05:52:24
【问题描述】:

我正在尝试为所有正在放映的电影搜索 http://www.regmovies.com/Theatres/Theatre-Folder/Regal-Meridian-16-1082 并返回它们的 imdb 评级。

从scrapy shell我设置了值:

fetch('http://www.regmovies.com/Theatres/Theatre-Folder/Regal-Meridian-16-1082')

response.xpath('//*[@id="content"]/div/div/div[2]/div[1]/div[7]/div[2]/div[1]/div/div[1]/h3/text()').extract()

返回值为空>>> [] 这是构建我的蜘蛛的最后一块。

【问题讨论】:

    标签: xpath scrapy


    【解决方案1】:

    此页面使用 JavaScipe 获取数据,您可以在 Chrome 开发工具的网络选项卡中找到数据 URL:

    你应该对这个 URL 使用 Scrapy Post 数据:

    In [9]: from scrapy.http import Request
    
    In [10]: r = Request(url='http://www.regmovies.com/services/MovieListings.asmx/TheatrePerformances',
        ...:             method='POST',
        ...:             body='{"tmsId":"AABFY","date":"Sun Mar 19 2017"}',
        ...:             headers={'Content-Type':'application/json', 'User-Agent':'Mozilla/5.0'})
    
    In [11]: fetch(r)
    2017-03-19 14:10:36 [scrapy.core.engine] DEBUG: Crawled (200) <POST http://www.regmovies.com/services/MovieListings.asmx/TheatrePerformances> (referer: None)
    
    In [12]: import json
    
    In [13]: json.loads(response.text) 
    

    输出:

    【讨论】:

      猜你喜欢
      • 2017-02-04
      • 1970-01-01
      • 2016-01-19
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多