2011-10-30 43 views
0

在我的html页面有两列的表格,第一个名称和第二个链接,其中有一个日期,我希望能够下载这个页面得到这个日期并提高它,所以在输出我会有名称和日期。 例如 在第一页我们在2564.html页有从内页获取数据并合并当前页面

<table> 
     <tr> 
     <td>A</td> 
     <td>http://something.com/2564.html</td> 
     </tr> 
</table> 

<body> 
    <p>the date is: 25 April 2009</p> 
</body> 

我怎么能有

<xml> 
    <row> 
     <name>A</name> 
     <date>25 April 2009</date> 
    </row> 
</xml> 
+0

当加载这个页面,你得到你所需要的所有的DOM元素。如果答案是肯定的,你可以使用sgml解析器,我会和你分享一些示例代码 –

回答

0

我的做法是创建项目,填写本页面中的数据,然后针对缺少数据的页面发出请求,并将该项目传递给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 data