with open 方法
for 循环写入 点write
image image一译中文官方文档:http://python.usyiyi.cn/
image image imageimage image
爬取《小王子》豆瓣短评的数据,并把数据保存为本地的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')
image image image
网友评论