一定是我的提問方式不對!
可能我是一個很不善於提問的人,尤其是和人類以外的物種交流,總會發生一些奇奇怪怪的對話。
關於全英羽毛球公開賽的資料,網上有很多,按爬取和解決問題的邏輯來看,搜索整合數據後再輸出應該不是太難的事兒。尤其是對於百科這類網站的數據,除了個別因素,多數內容都能用來學習。
先公布正常答案:
換句話說:ChatGPT,開卷考試,告訴答案在哪一行,還為什麼還回答不對問題呢?
下面這一張,可能是最離譜的答案了,裡面匯聚了各行各業的知名人士。
難道,真的要告訴你:用 php 或者 python 抓取網頁 'https://zh.m.wikipedia.org/wiki/全英羽毛球公開錦標賽' 中「奪冠次數較多者」後面的第一個 table 數據中前20列並輸出姓名、男單、女單、男雙、女雙、混雙和合計奪冠次數?
既然想到了,那就試試:
import requests
from bs4 import BeautifulSoup
# 獲取網頁內容
url = "https://en.wikipedia.org/wiki/All_England_Open_Badminton_Championships"
html = requests.get(url).text
# 解析HTML
soup = BeautifulSoup(html, 'html.parser')
# 找到「Multiple winners」後面的第一個table
table = soup.find('table', {'class': 'wikitable sortable'})
# 輸出前20行數據
print('{:<30} {:<10} {:<10} {:<10} {:<10} {:<10} {:<10}'.format('Name', 'MS', 'WS', 'MD', 'WD', 'XD', 'Total'))
for row in table.find_all('tr')[1:21]:
cols = row.find_all('td')
name = cols[0].get_text().strip()
ms = cols[1].get_text().strip()
ws = cols[2].get_text().strip()
md = cols[3].get_text().strip()
wd = cols[4].get_text().strip()
xd = cols[5].get_text().strip()
total = cols[6].get_text().strip()
print('{:<30} {:<10} {:<10} {:<10} {:<10} {:<10} {:<10}'.format(name, ms, ws, md, wd, xd, total))
可是輸出的結果居然是:
Name MS WS MD WD XD Total
George Alan Thomas 4 1 9 0 8 21
Erland Kops 5 0 2 0 1 8
Rudy Hartono 8 0 0 0 0 8
Gillian Gilks 0 1 0 4 5 10
Eddie Choong 5 0 4 0 1 10
Morten Frost 4 0 0 0 0 4
Lin Dan 6 0 0 0 0 6
Peter Gade 5 0 0 0 0 5
Nora Perry 3 3 0 0 0 6
Yang Yang (singles) 4 0 0 0 0 4
Christian Hadinata 0 0 4 4 4 12
Rexy Mainaky 0 0 6 1 4 11
Zhao Yunlei 0 2 2 2 5 11
Li Lingwei 0 4 0 0 0 4
Park Joo-bong 0 0 8 1 1 10
Kim Dong-moon 0 0 8 0 0 8
Gao Ling 0 0 0
哪裡出了問題?有沒有人幫看下,python我不熟。結果可以說是讓人很失望了。
現在我的問題是,如何提問,才能讓ChatGPT生成正確答案。雖然我直接看維基百科可以得到答案,但在內心深入始終希望有一天,當人類只能通過對話提問的方式,來面對ChatGPT這樣的唯一終端時,它不以欺騙我們百科全書看得少。