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