2011-10-30 33 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