2 回答
TA贡献1806条经验 获得超8个赞
尝试这个,
import requests
from bs4 import BeautifulSoup
resp = requests.get("https://www.simplyrecipes.com/recipes/egg_salad_sandwich/")
soup = BeautifulSoup(resp.text, "html.parser")
div_ = soup.find("div", attrs={"class": "recipe-callout"})
recipes = {"_".join(div_.find("h2").text.split()):
[x.text for x in div_.findAll("li", attrs={"class": "ingredient"})]}
TA贡献1966条经验 获得超4个赞
听起来你的代码应该在下面,在我删除了不必要的h3检索之后
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path)
webpage_url = 'https://www.simplyrecipes.com/recipes/egg_salad_sandwich/'
browser.visit(webpage_url)
time.sleep(1)
website_html = browser.html
website_soup = BeautifulSoup(website_html, 'html.parser')
ingredientsList = website_soup.find('li', class_ = "ingredient")
print({ingredients})
您正在尝试查找具有不存在的类名的h3元素Ingredients
添加回答
举报