Skip to content

Commit 3986880

Browse files
author
Jay
committed
update
1 parent 2bcfd62 commit 3986880

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

app.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from flask import Flask, render_template, request, jsonify, redirect, make_response, url_for, flash
2-
from recipe_scrapers import scrape_me, WebsiteNotImplementedError, SCRAPERS
2+
from recipe_scrapers import scrape_html, WebsiteNotImplementedError, SCRAPERS
33
import urllib
44
import parsers
55
import logging
@@ -41,7 +41,11 @@ def scrape_recipe(url):
4141

4242
if not recipe:
4343
try:
44-
scraper = scrape_me(url)
44+
headers = {
45+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
46+
}
47+
resp = requests.get(url, headers=headers).text
48+
scraper = scrape_html(resp, org_url=url)
4549
instructions = [i.strip() for i in scraper.instructions().split("\n") if i.strip()]
4650
recipe = {
4751
'name': scraper.title(),

parsers/recipe.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def fetch_html(self, url):
1313
#fd = open('allrecipes3.html', 'r')
1414
#return fd.read()
1515

16-
content = requests.get(url)
16+
headers = {
17+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
18+
}
19+
content = requests.get(url, headers=headers)
1720
return content.text
1821

1922
def fetch_soup(self, url):

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
beautifulsoup4>=4.12.3
22
Flask==3.0.3
33
gunicorn==22.0.0
4-
recipe-scrapers==14.58.0
4+
recipe-scrapers==15.2.1

0 commit comments

Comments
 (0)