Python For Loop - Hierachy

时间:2018-01-26 23:57:37

标签: python beautifulsoup

我正在尝试进行一些网络抓取,然后运行两个for循环来深入研究,我最终想要的是网络链接href。

website_details = soup.find_all("div", attrs={'class': 'bodyText'})
result = []
for tag in website_details:
    result.append(tag)

result2 = []
p_tag = result.find_all("p")
for tag in p_tag:
    result2.append(tag)

我收到以下错误。

  

p_tag = result.find_all(“p”)
  AttributeError:'list'对象没有属性'find_all'

1 个答案:

答案 0 :(得分:3)

这是因为result是python listlist没有find_all()函数。

您需要在汤品上调用find_all()(可能在website_details上?)。