0
我正在使用Python 2.7腳本從網站中提取日期。代碼如下:lxml/xpath - 限制輸出
from lxml import html, etree
from urllib2 import urlopen
import requests
url = 'http://www.cardiffdevils.com/fixtures/'
newtree = etree.HTML(urlopen(url).read())
for section in newtree.xpath('//div[@class="month"]'):
print section.xpath('h3[1]/text()')
print section.xpath('//td[@class="date"]/text()')
的幾個月正在輸出正確的,但我想限制打印的每一部分,只有那些相應的「月」類中發現的日期;目前它將所有日期發現在整個頁面中。任何指針將不勝感激!
你我是一個學者,(我認爲)是一位紳士,這正是我所需要的。謝謝! –