Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tilalis/599202db0a136b6896f435b2bde1ab07 to your computer and use it in GitHub Desktop.
Save tilalis/599202db0a136b6896f435b2bde1ab07 to your computer and use it in GitHub Desktop.
import requests
import re
from bs4 import BeautifulSoup
#вызываемая функция для каждого раздела
def parse(page):
global kek
htmlPage = requests.get(page)
soup = BeautifulSoup(htmlPage.text , "html.parser")
while (soup.find('a' , id="link-pagination-next")) :
tmp = [tag['href'] for tag in soup.findAll("a", id=re.compile("link-recipewidget-recipeName-[0-9]*"))]
for item in tmp :
if item.startswith(page):
file.write(item+'\n')
htmlPage = requests.get(soup.find('a' , id="link-pagination-next")['href'])
soup = BeautifulSoup(htmlPage.text, "html.parser")
print(kek)
kek += 1
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
#сама программа
kek = 0
file = open('links.txt' , 'w' )
#список ссылок на разделы сайта
links = ['http://eda.ru/recepty/vypechka-deserty' , 'http://eda.ru/recepty/osnovnye-blyuda' , 'http://eda.ru/recepty/zavtraki' ,
'http://eda.ru/recepty/salaty' , 'http://eda.ru/recepty/supy' , 'http://eda.ru/recepty/pasta-picca'
'http://eda.ru/recepty/zakuski' , 'http://eda.ru/recepty/sendvichi' , 'http://eda.ru/recepty/rizotto' ,
'http://eda.ru/recepty/napitki' , 'http://eda.ru/recepty/sousy-marinady' , 'http://eda.ru/recepty/bulony']
for item in links :
parse(item)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment