【发布时间】:2018-11-23 13:26:29
【问题描述】:
我搜索了类似的问题,但没有找到我需要的。
我正在网上搜索两个属性,在这种情况下是 red 和 green in span
from urllib.request import urlopen
from bs4 import BeautifulSoup
html=urlopen('http://www.pythonscraping.com/pages/warandpeace.html')
soup=BeautifulSoup(html,'html.parser')
nameList=soup.findAll("span",{"class":"red","class":"green"})
print(nameList)
但是我只获得了绿色属性,我尝试使用
nameList,nameList2=soup.findAll("span",{"class":"red","class":"green"})
但我收到错误ValueError: too many values to unpack (expected 2)
有没有办法同时打印并将每个属性存储在名单中(不使用多个findAll)
【问题讨论】:
标签: python web-scraping findall