在我的html页面中有两列表,第一列是名称,第二列是链接,其中有一个 Date ,我希望能够下载这个页面获取这个date并引发它,所以在输出中我将有名称和日期。例如,在我们的第一页中
<table>
<tr>
<td>A</td>
<td>http://something.com/2564.html</td>
</tr>
</table>在2564.html页面中有
<body>
<p>the date is: 25 April 2009</p>
</body>我怎么能有
<xml>
<row>
<name>A</name>
<date>25 April 2009</date>
</row>
</xml>发布于 2011-11-01 13:14:05
我的方法是创建项目,用页面上的数据填充它,然后在meta中传递条目,向页面发出一个包含缺失数据的请求。当下载第二页时,我从meta获取项目并填充其他数据:
def parseItem(self, response):
'''Get date from the first page.'''
item = Item()
item['firstdata'] = '???'
...
otherDataPageLink = '???'
yield Request(otherDataPageLink, meta = {'item': item}, callback = self.parseComments)
def parseComments(self, response):
'''Get all the other data from second page.'''
item = response.meta['item']
item['otherdata'] = '???'
yield item # return the item with all the datahttps://stackoverflow.com/questions/7944802
复制相似问题