I have some python 3.5 code that I want to scrape part of a web page with but instead of printing "Thick and Chewy Peanut Butter Chocolate Chip Bars" it prints "None". Do you know why? Thanks.
import requests, bs4
import tkinter as tk
from tkinter import *
import pymysql
import pymysql.cursors
res = requests.get("http://www.foodnetwork.co.uk/article/traybake-recipes/thick-and-chewy-peanut-butter-chocolate-chip-bars/list-page-2.html")
res.raise_for_status()
recipeSoup = bs4.BeautifulSoup(res.text, "html.parser")
type(recipeSoup)
instructions = recipeSoup.find("div", itemprop="name")
try:
method = str.replace(instructions.get_text(strip=True),". ",".")
method = str.replace(method, ". ", ".")
method = (str.replace(method, ".",".\n"))
except AttributeError:
print(instructions)
Link to scraped page
Change instructions = recipeSoup.find("div", itemprop="name")
to instructions = recipeSoup.find("span", itemprop="name")
to get the recipe title.
For the instructions you'll have to search for li
tags with itemprop=ingredients
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With