【发布时间】:2017-02-25 23:04:31
【问题描述】:
我正在使用 lxml 库在 python 中进行网络抓取。而且,我正试图从棒球网站http://mlb.mlb.com/mlb/standings/exhibition.jsp?ymd=20161002 上刮取一些数据。 出于某种原因,我的代码在我之前打印的内容之后打印了一个空列表。在这个问题上的任何帮助都会很棒!
from lxml import html
import requests
page = requests.get('http://mlb.mlb.com/mlb/standings/exhibition.jsp?ymd=20161002')
tree = html.fromstring(page.content)
#This will create a list of buyers:
##buyers = tree.xpath('//div[@title="buyer-name"]/text()')
#This will create a list of prices
prices = tree.xpath('//td[@class="tg_w"]/text()')
print("Wins: ", prices)
print()
##print("Buyers: ", buyers)
【问题讨论】:
-
我的猜测是您正在获取的页面不包含表格元素(td),它们是由 javascript/ajax 加载的,因此您可能会寻找 mlb.mlb.com 的 api
标签: python xpath web-scraping lxml