Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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-response.xpath将项目分开返回_Python_Web Scraping_Scrapy - Fatal编程技术网

Python Scrapy-response.xpath将项目分开返回

Python Scrapy-response.xpath将项目分开返回,python,web-scraping,scrapy,Python,Web Scraping,Scrapy,我正在尝试刮取第一页上有多个博客条目的网页。 这是我目前的代码: for rel in response.xpath('//*[@id="content"]/div[*]/div/comment()[2]'): item = Example() item['title'] = rel.xpath('//*[@id="content"]/div[*]/div/div/input/@value').extract() item['link'] = rel.xpath('//*

我正在尝试刮取第一页上有多个博客条目的网页。
这是我目前的代码:

for rel in response.xpath('//*[@id="content"]/div[*]/div/comment()[2]'):
    item = Example()
    item['title'] = rel.xpath('//*[@id="content"]/div[*]/div/div/input/@value').extract()
    item['link'] = rel.xpath('//*[@id="content"]/div[*]/div/div/span[4]/a/@href').extract()
    yield item
问题是如果我使用
“*”
我会得到一个包含所有条目的链接和标题。
但我希望每个条目都有一个标题和一个链接。
我对Python和
scrapy
非常陌生,不知道如何计数才能找回单个条目。

第一个条目以
“2”
开始,下一个条目是
+3
,直到它在29结束。(2,5,8…29)

让我建议更明确的XPath。类似的东西应该更接近你的目标:

for rel in response.xpath('//div[@class="beschreibung"]'):
    item['title'] = rel.xpath(".//strong[contains(text(),"Release")]/following-sibling::*[1]/@value").extract()
    item['link'] = rel.xpath('.//span[@style="display:inline;"]//a[contains(text(),"Share")]/@href').extract()
    yield item

你能提供一个网页的HTML样本吗?当然,网页是。希望如此,为每个条目从开始刮取发布条目。