image
image
image
with open 方法
for 循環(huán)寫入 點(diǎn)write
image
image
一譯中文官方文檔:http://python.usyiyi.cn/
image
image
image
image
image
爬取《小王子》豆瓣短評(píng)的數(shù)據(jù),并把數(shù)據(jù)保存為本地的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