Python/Xpath如何刮取href字段

2024-05-23 17:03:27 发布

您现在位置:Python中文网/ 问答频道 /正文

作为一个例子,我想从下面的页面中提取团队名称

http://www.scoresandodds.com/grid_20150409.html

我试过了:

from lxml import html
import requests

pageNBA = requests.get('http://www.scoresandodds.com/grid_20150409.html')
treeNBA = html.fromstring(pageNBA.text)
team = treeNBA.xpath('//a[@href="/statfeed/statfeed.php?page=nba/nbateam&teamid=CHICAGO&season="]/text()')

我想我的问题是在我定义位置的团队线中,我应该如何定位a href。在


Tags: textimportcomhttphtmlwww团队requests