我有一個網站上的以下表,我與BeautifulSoup 提取這是URL(我還附上了圖片獲取表的內容BeautifulSoup
理想我想有每家公司在一個排在CSV但是我得到它在不同的行。請參見圖片連接。
我想它有它像場「d」但我得到它在A1,A2,A3 ...
這是我用來提取代碼:
def _writeInCSV(text):
print "Writing in CSV File"
with open('sara.csv', 'wb') as csvfile:
#spamwriter = csv.writer(csvfile, delimiter='\t',quotechar='\n', quoting=csv.QUOTE_MINIMAL)
spamwriter = csv.writer(csvfile, delimiter='\t',quotechar="\n")
for item in text:
spamwriter.writerow([item])
read_list=[]
initial_list=[]
url="http://www.nse.com.ng/Issuers-section/corporate-disclosures/corporate-actions/closure-of-register"
r=requests.get(url)
soup = BeautifulSoup(r._content, "html.parser")
#gdata_even=soup.find_all("td", {"class":"ms-rteTableEvenRow-3"})
gdata_even=soup.find_all("td", {"class":"ms-rteTable-default"})
for item in gdata_even:
print item.text.encode("utf-8")
initial_list.append(item.text.encode("utf-8"))
print ""
_writeInCSV(initial_list)
有人可以幫助嗎?
它甚至會更好,我可以複製整個表以CSV但我用怎麼辦掙扎是 – Nant