Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Scrapy请求以某种方式削减了URL_Python_Scrapy - Fatal编程技术网

Python Scrapy请求以某种方式削减了URL

Python Scrapy请求以某种方式削减了URL,python,scrapy,Python,Scrapy,我喜欢抓取一个如下所示的url: 因为结束是动态的,所以我在解析中创建URL列表,然后进行请求循环 问题是,他在appid=730之后剪切url,因此每个url看起来都一样。如果我切换到dont_filter=true,我会看到他在第1页上一次又一次地循环。我不明白这个问题: 代码中的x稍后将变得动态,这是开始url所需要的,认为这与问题无关 似乎他总是从引用者的url中爬行,而不是我给他的那个。url不能以730结尾 调试消息: 预期:150个结果,循环中每个url对应10个结果 实际:15

我喜欢抓取一个如下所示的url:

因为结束是动态的,所以我在解析中创建URL列表,然后进行请求循环

问题是,他在appid=730之后剪切url,因此每个url看起来都一样。如果我切换到dont_filter=true,我会看到他在第1页上一次又一次地循环。我不明白这个问题:

代码中的x稍后将变得动态,这是开始url所需要的,认为这与问题无关

似乎他总是从引用者的url中爬行,而不是我给他的那个。url不能以730结尾

调试消息: 预期:150个结果,循环中每个url对应10个结果


实际:15个结果,但每10次-全部从第一个url开始。

地址栏上的url如您所说显示,但如果您在浏览器开发人员工具的“网络”选项卡上检查请求,您将看到返回新项目的请求如下:

此Json包含字段results_HTML上的页面HTML,如果希望使用xpath获取数据,可以使用此值创建选择器

import json

def parse(self, response):
    data = json.loads(response.text)
    sel = scrapy.Selector(text=data['results_html'])
    # then use sel
    value = sel.xpath('//value').get()
阅读此URL的响应时,您还可以注意到有一条提示,说明也可以向URL添加参数&norender=1,而不使用HTML。所以,你可以选择你最喜欢的

很多网站都这样做,所以你必须关注请求,不要总是相信地址栏上显示的内容。我建议您永远不要相信inspector上显示的内容,始终检查源代码右键单击>查看页面源代码

allowed_domains = ['steamcommunity.com/market']
start_urls = ['https://steamcommunity.com/market/search?appid=730']

def parse(self, response):
    x = 15 
    steam_xpath = [u'//steamcommunity.com/market/search?appid=730#p'+str(i)+'_popular_desc' for i in range(1, x)]
    for link in steam_xpath:
        yield Request(response.urljoin(link), self.parse_steam, dont_filter=True)

def parse_steam(self, response):
    xitem_name = response.xpath('//span[@class="market_listing_item_name"]/text()').extract()
    xitem_price = response.xpath('//span[@class="normal_price"]/text()').extract()
    xitem_subtext = response.xpath('//span[@class="market_listing_game_name"]/text()').extract()
    xitem_count = response.xpath('//span[@class="market_listing_num_listings_qty"]/text()').extract()
    for item in zip(xitem_name, xitem_price, xitem_subtext, xitem_count):
        new_item = SteammarketItem()
        new_item['item_name'] = item[0]
        new_item['item_price'] = item[1]
        new_item['item_subtext'] = item[2]
        new_item['item_count'] = item[3]
        yield new_item
import json

def parse(self, response):
    data = json.loads(response.text)
    sel = scrapy.Selector(text=data['results_html'])
    # then use sel
    value = sel.xpath('//value').get()