Python爬取问卷星内容

Python爬取问卷星内容

问卷星标题和选项内容爬取
从以下博客中学习到的,加了些自己的解释
Python3 爬虫— 问卷星内容爬取
先贴代码:

import time
from requests_html import HTMLSession
 

wenjuanxing_URL = "https://ks.wjx.top/jq/55123312.aspx"
 
 
def parse_post_data(resp):
    questions = resp.html.find('fieldset', first=True).find('.div_question')
 
    for i, q in enumerate(questions):
        title = q.find('.div_title_question_all', first=True).text
        choices = [t.text for t in q.find('label')]
        print(title)
        for choice in choices:
            print(choice)
        print('***************************************************\n')
        time.sleep(0.5)


def main():
    print('开始爬取问卷内容')
    print('链接:%s' % wenjuanxing_URL)
    session = HTMLSession()
    resp = session.get(wenjuanxing_URL)
    parse_post_data(resp)


if __name__ == '__main__':
    main()

需要导入time和requests_html包,没有的可以在python目录下用pip下载

questions = resp.html.find('fieldset', first=True).find('.div_question')

这里的filedset是包含所有题目和答案的标签

题目内容

title = q.find('.div_title_question_all', first=True).text

对应题目选项

choices = [t.text for t in q.find('label')]

控制台运行:
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值