用python+BeautifulSoup爬百度知道的答案 您所在的位置:网站首页 百度问答最佳答案 用python+BeautifulSoup爬百度知道的答案

用python+BeautifulSoup爬百度知道的答案

#用python+BeautifulSoup爬百度知道的答案| 来源: 网络整理| 查看: 265

因需要一些资料,就写了个爬虫爬取百度知道前N页的所有答案 不过鉴于百度知道的回答质量(你懂得。。。。),爬取的内容仅供参考

替换一下url_root和file_name基本就能通用了 注:每个网站使用的标签不一样,代码仅适用于百度知道,其他网站自行修改 在这里插入图片描述

# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup import lxml url_root = 'https://zhidao.baidu.com/search?word=%C0%F8%D6%BE%B6%CC%BE%E4&ie=gbk&site=-1&sites=0&date=0&pn=0' file_name = 'C:\\Users\\username\\Desktop\\sort_statement.txt' # 获取下一页的url def get_next(url): strhtml = requests.get(url) soup = BeautifulSoup(strhtml.text, 'lxml'


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有