【发布时间】:2020-03-13 03:56:13
【问题描述】:
def getDOW():
DowURL = ["https://finance.yahoo.com/quote/%5EDJI?p=^DJI"]
# requests data on the website(s) above
page = requests.get(DowURL, headers=headers)
# parses HTML text from website
soup = BeautifulSoup(page.content, "html.parser")
# title = soup.find(class_="D(ib) Fz(18px)").get_text()
name = soup.find(class_= "Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)").get_text()
print (name)
返回错误:
raise InvalidSchema("No connection adapters were found for '%s' % url")
requests.exceptions.InvalidSchema: No connection adapters were found for '['https://finance.yahoo.com/quote/%5EDJI?p=^DJI']'
很抱歉,如果之前有人问过这个问题,但我是 BeautifulSoup 的新手,所以我不确定发生了什么。如果有人可以帮助我或建议我,将不胜感激。我正在尝试从多个站点抓取值,但未能使用列表执行此操作,因此创建了单独的函数(我知道这是多么多余)并遇到此错误。
【问题讨论】:
-
为什么使用 URL 列表?您需要提供一个 URL(字符串)或索引您的列表
DowURL[0]。 -
是的,我注意到括号是问题所在。谢谢@HTF
标签: python beautifulsoup python-requests