Forked from lamerocheg/gist:af85cf7c846bd377d2af52646d05e186
Created
April 12, 2016 20:13
-
-
Save tilalis/599202db0a136b6896f435b2bde1ab07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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