http://www.baseball-reference.com/players/event_hr.cgi?id=bondsba01&t=b
,並試圖刮掉從表中的數據上。當我拉的XPath從一個條目,說投手 「特里穆赫蘭,」我檢索此:
pitchers = site.xpath("/html/body/div[2]/div[2]/div[6]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/a)
當我嘗試打印pitcher[0].text
用於打印機的投手,我得到[]
而非text
,任何想法爲什麼?
html不是xml。使用BeautifulSoup解析html。 – 2012-02-14 04:01:57
FUD。 lxml適用於解析HTML,xpath適用於HTML dom導航。 – 2012-02-14 04:29:40
因此,lxml.html包。 – 2012-02-14 04:30:04