python最简单爬虫入手例子之一:

python最简单爬虫入手例子:

爬取某网站书籍评论

import requests
from bs4 import BeautifulSoup
import pandas as pd

url = 'https://www.aliwx.com.cn/comment?bookid=7178107&authorid=2371187'
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
headers = {"User-Agent": user_agent}

inform_list = []

respond = requests.get(url=url, headers=headers)
soup = BeautifulSoup(respond.text, 'lxml')

div_list = soup.find_all('div', class_="comment")

for node in div_list:
    comment = node.find('p', class_='content js-textArea').text
    print(comment)
    inform_list.append(comment)

在这里插入图片描述

发布了15 篇原创文章 · 获赞 18 · 访问量 915

猜你喜欢

转载自blog.csdn.net/weixin_44983848/article/details/105563131
今日推荐