2017-03-07 9 views
0

Ich habe einige Python 3.5 Code, den ich Teil einer Webseite mit kratzen möchte, aber anstatt "dicke und zähen Erdnussbutter Chocolate Chip Bars" drucken druckt es "keine". Weißt du, warum? Vielen Dank.BeautifulSoup scrape itemprop = "name" in Python

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

Antwort

1

ändern instructions = recipeSoup.find("div", itemprop="name") zu instructions = recipeSoup.find("span", itemprop="name") das Rezept Titel zu bekommen. Für die Anweisungen müssen Sie nach li Tags mit itemprop=ingredients suchen.