擅长:python、mysql、java
<p>或者您可以简单地使用pandas来创建csv函数:</p>
<pre><code>import pandas as pd
from pandas import DataFrame as df
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.officialcharts.com/charts/singles-chart/19800203/7501/" )
bsObj = BeautifulSoup(html)
DB = df(columns = ['artists','songs'])
artistList = bsObj.findAll("div", {"class": "artist"})
songList = bsObj.findAll("div", {"class": "title"})
DB['artists'] = [ a.getText().strip() for a in artistList ]
DB['songs'] = [ s.getText().strip() for s in songList ]
DB.to_csv('csvfile.csv')
</code></pre>