5 pandas報存數據


with open 方法
for 循環寫入 點write

一譯中文官方文檔:http://python.usyiyi.cn/







爬取《小王子》豆瓣短評的數據,並把數據保存爲本地的excel表格
import requests
from lxml import etree

url = 'https://book.douban.com/subject/1084336/comments/'
r = requests.get(url).text

s = etree.HTML(r)
file = s.xpath('//div[@class="comment"]/p/text()')

import pandas as pd
df = pd.DataFrame(file)
df.to_excel('pinglun.xlsx')



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章