使用 Beautiful Soup 抓取网站正在返回字符串列表而不是列表列表。
我尝试了一个 .replace 但它不能在循环中的列表上工作。
import bs4 as bs
import urllib.request
import csv
import pandas as pd
source = 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)
噜噜哒
相关分类