吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1142|回复: 0
收起左侧

[已解决] python 爬取网站单选题-问题已解决

[复制链接]
akon007 发表于 2020-3-23 17:29
本帖最后由 akon007 于 2020-3-23 17:36 编辑

from bs4 import BeautifulSoup
import requests

hds = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
     }
'''

url = 'https://xxx/xxxx/detail?id=3996'
r = requests.get(url=url,headers=hds)
sources = r.content
soup = BeautifulSoup(sources,'lxml')
# print(soup.find('div',class_='J_SubjectList'))
soup_new = soup.findAll('a',class_= 'subject-tit')
for chapters in soup_new:
    if 'paper' in chapters.attrs['href']:
        print(chapters.text)
        print(f"http://xxxx/{chapters.attrs['href']}")
'''
url2 ='http://xxxx/view-2570724.shtml'
r2 = requests.get(url=url2,headers=hds)
sources = r2.content
soup2 = BeautifulSoup(sources,'lxml')
#print(soup2)
questions = soup2.find_all('div',attrs={'class':'q-tit'})
options = soup2.find_all('div',attrs={'class':'exam-s'})
for question in questions:
    for option in options:
        print(question.text.replace('\n',''))
        print(option.text)**** 1.   Students in Grade Nine ____________a maths exam at this time yesterday.A . takeB . are takingC . were takingD . have taken

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-26 18:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表