最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

BeautifulSoup

旗下网站admin8浏览0评论

BeautifulSoup

BeautifulSoup

BeautifulSoup - str对象没有属性findAll(BeautifulSoup - str object has no attribute findAll)

我正在使用BeautifulSoup来抓取股票代码数据,但我遇到了使用findAll()的问题

import urllib.requestfrom bs4 import BeautifulSoupimport requestsimport collectionsdef findCSV(soupPage): CSV_URL_PREFIX = '.csv?s=' links = soupPage.findAll('a') for link in links: href = link.get('href', '') if href.startswith(CSV_URL_PREFIX): return href

我收到错误:

str对象没有属性findAll

我不确定是什么导致了这个问题,因为我过去在一个非常类似的实现中成功使用了findAll() 。

I'm using BeautifulSoup to crawl stock ticker data, but I'm running into an issue using findAll()

import urllib.requestfrom bs4 import BeautifulSoupimport requestsimport collectionsdef findCSV(soupPage): CSV_URL_PREFIX = '.csv?s=' links = soupPage.findAll('a') for link in links: href = link.get('href', '') if href.startswith(CSV_URL_PREFIX): return href

I get the error:

str object has no attribute findAll

I'm not sure what's causing this problem, because I have used findAll() successfully in the past in a very similar implementation.

最满意答案

该错误不在您提供的代码示例中:如错误消息所示,您已调用findCSV函数findCSV传递字符串。

# you did this: my_string = "hello" findCSV(my_string) # instead of soup = BeautifulSoup('<html..></html>') findCSV(soup)

The bug is not in the code sample that you have provided: as the error message indicates, you have called the findCSV function passing it a string.

# you did this: my_string = "hello" findCSV(my_string) # instead of soup = BeautifulSoup('<html..></html>') findCSV(soup)

发布评论

评论列表(0)

  1. 暂无评论