获取网站评论

import requests
from lxml import etree
import csv

url = '***********'
resq = requests.get(url)
html = etree.HTML(resq.text)

uls = html.xpath('/html/body/div[2]/div[1]/div[5]/div[4]/ul/li')  # 要获取的路径

fb = open('评价.csv', mode='w')  # 创建文件
f = csv.writer(fb)
for ul in uls:
    comm_cont = ul.xpath('./div/div[3]/text()')[0]  # 获取评论内容
    UserName = ul.xpath('./div/div[2]/a/text()')[0]  # 获取评论人员昵称
    a = f'{UserName}:{comm_cont}'
    f.writerow(a.split(','))  # 切割保存
fb.close()

你可能感兴趣的:(随笔记,java,html,前端,其他)