5 pandas报存数据
2018-02-01 本文已影响14人
怂恿的大脑
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')