我在网上抓取与lxml库的python。并且,我试图从棒球网站http://mlb.mlb.com/mlb/standings/exhibition.jsp?ymd=20161002刮掉一些数据。 出于某种原因,我的代码在之前打印的内容后打印出一个空列表。任何关于这个问题的帮助都会很棒!Web Scraping标签问题 - Python 3与Lxml
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。 – suhain