我在網上抓取與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