亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Beautiful Soup scrape of table 正在返回字符串列表而不是列表列表

Beautiful Soup scrape of table 正在返回字符串列表而不是列表列表

拉莫斯之舞 2022-06-14 09:55:57
使用 Beautiful Soup 抓取網站正在返回字符串列表而不是列表列表。我嘗試了一個 .replace 但它不能在循環中的列表上工作。import bs4 as bsimport urllib.requestimport csvimport pandas as pdsource = urllib.request.urlopen('https://www.basketball-reference.com/players/d/duncati01/gamelog/2015').read()soup = bs.BeautifulSoup(source,'lxml')f = csv.writer(open('bball_ref.csv','w'))body = soup.body    table = soup.select('#pgl_basic')table_rows = table[0].find_all('tr')for tr in table_rows:    td = tr.find_all('td')    row = [i.text for i in td]    f.writerow([row])with open('bball_ref.csv') as csvfile:    bball_ref = csv.reader(csvfile,delimiter=",")    rows = []    for row in bball_ref:        rows.append(row)
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

row已經是一個列表,調用時不需要在其周圍放置另一個列表f.writerow()。它應該是

f.writerow(list)


查看完整回答
反對 回復 2022-06-14
  • 1 回答
  • 0 關注
  • 76 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號