我正在尝试编写一个小脚本来遍历quotedb网站以获取当天的报价,我正在使用bs4
如何遍历返回的内容以查找当天的报价?
事情是,我发现很难遍历甚至理解网站的内容。我从哪里开始或者我该怎么做?
答案 0 :(得分:2)
代码:
import requests, re
from bs4 import BeautifulSoup
get_page = requests.get("https://www.quotedb.com/")
soupify = BeautifulSoup(get_page.text, 'html.parser')
quote = soupify.find('a', href=re.compile('//www.quotedb.com/quote'))
print(quote.text)
输出:
"The President of the United States hears a hundred voices telling him that he is the greatest man in the world. He must listen carefully to hear the one voice that tells him he's not."