擅长:python、mysql、java
<p>您可以使用<code>find_all</code>来定义<code>bar</code>。所以<code>bar</code>是一个列表,没有<code>text</code>属性。在循环的<code>div</code>变量上使用<code>find</code>,而不是<code>find_all</code>。就像这样:</p>
<pre class="lang-py prettyprint-override"><code>import requests
import bs4
import lxml
result=requests.get("https://www.1mg.com/drugs-all-medicines")
#print((type(result)))
soup = bs4.BeautifulSoup(result.text,"lxml")
#print(soup)
scrape=soup.find_all('div', attrs={'class': 'style__font-bold___1k9Dl style__font-14px___YZZrf style__flex-row___2AKyf style__space-between___2mbvn style__padding-bottom-5px___2NrDR'})
for div in scrape:
bar=div.find('div')
print(bar.text)
</code></pre>
<p>(您也可以参考<a href="https://stackoverflow.com/a/22217852/13123142">this answer</a>)</p>