如何从 Quizlet 抽认卡中抓取答案? BS4 和要求

问题描述 投票:0回答:2

以此页面为例:

https://quizlet.com/229413256/chapter-6-configuring-networking-flash-cards/

假设一个人如何从抽认卡后面刮掉文本答案?它现在是隐藏的,但是当您单击它时,它会旋转并显示答案。

到目前为止我所看到的看起来像这样,但我确信没有选择正确的元素:

def find_quizlet_flashcard_answer(quizlet_url):

    # desktop user-agent
    USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
    # mobile user-agent
    MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36"
    headers = {"user-agent": USER_AGENT}
    
    resp = requests.get(quizlet_url, headers=headers)

    if resp.status_code == 200:
        soup = BeautifulSoup(resp.content, "html.parser")
        inner_divs = soup.find_all("div", {"aria-hidden": "true"})
        for g in inner_divs:
            result = g.text
            print(result)
    return result
python-3.x beautifulsoup python-requests
2个回答
4
投票

要获取所有问题和答案,您可以使用此示例:

import requests
from bs4 import BeautifulSoup


url = 'https://quizlet.com/229413256/chapter-6-configuring-networking-flash-cards/'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')

for i, (question, answer) in enumerate(zip(soup.select('a.SetPageTerm-wordText'), soup.select('a.SetPageTerm-definitionText')), 1):
    print('QUESTION {}'.format(i))
    print()
    print(question.get_text(strip=True, separator='\n'))
    print()
    print('ANSWER:')
    print(answer.get_text(strip=True, separator='\n'))
    print('-' * 160)

打印:

QUESTION 1

Which of the following are true regarding IPv4?
a. 32-bit address
b. 128-bit address
c. Consists of a network ID and MAC address
d. Consists of a host ID and MAC address

ANSWER:
a. 32-bit address
----------------------------------------------------------------------------------------------------------------------------------------------------------------
QUESTION 2

How many bits does a standard IPv6 unicast address use to represent the network ID?
a. 32
b. 64
c. 128
d. 10

ANSWER:
b. 64
----------------------------------------------------------------------------------------------------------------------------------------------------------------
QUESTION 3

Which of the following Windows PowerShell commands performs a DNS name query for www.contoso.com?
a. ping www.contoso.com
b. dnsquery www.contoso.com
c. resolve-DNSName -Name www.contoso.com
d. resolve-DNSquery www.comcast.net

ANSWER:
c. resolve-DNSName -Name www.contoso.com
----------------------------------------------------------------------------------------------------------------------------------------------------------------


...and so on.

0
投票

有没有办法消除课本答案的模糊性?

© www.soinside.com 2019 - 2024. All rights reserved.