gpt4 book ai didi

python-3.x - 如何从 Quizlet 抽认卡中抓取答案? BS4 和要求

转载 作者:行者123 更新时间:2023-12-04 14:11:19 24 4
gpt4 key购买 nike

以本页为例:

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

最佳答案

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

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.

关于python-3.x - 如何从 Quizlet 抽认卡中抓取答案? BS4 和要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com