<jupyter_start><jupyter_text>дата источник(урл) название текст<jupyter_code>def get_date(num):
    days = []
    for i in range(num)[1:]:
        days.append( str((datetime.date.today()-datetime.timedelta(days=i))).replace('-','/') )
    return days
def get_titles(data):
    r = requests.get('https://lenta.ru/'+data) #'/2019/05/19' формат
    soup = BeautifulSoup(r.content)
    title = [(i.a['href'], i.a.span.text.replace('\xa0', ' ')) for i in soup.find_all('div', {"class":"titles"})]
    return title
def get_text(url):
    try:
        rq = requests.get('https://lenta.ru'+url)
        soup_new = BeautifulSoup(rq.content)
        text = ''.join([i.text for i in soup_new.find_all('p')])
        return text
    except:
        print('error')
        return 'None'

def writer(name,num):
    df = pandas.DataFrame(columns=["date","url","title","text"])
    for date in tqdm.tqdm_notebook(get_date(num)):
        for i in tqdm.tqdm_notebook(get_titles(date)):
            txt = get_text(i[0])
            dct = {"date": date, 
                   "url": 'https://lenta.ru'+i[0],
                   "title": i[1],
                   "text": txt}
            df = df.append(dct, ignore_index=True)
    df.to_csv(name)
    return df
df = writer('file.csv',30)
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18146718146718147, 'fraction_numerical': 0.011583011583011582, 'mean_word_length': 2.6923076923076925, 'pattern_counts': {'":': 5, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '16184', 'license': 'MIT', 'n_tokens_mistral': 486, 'n_tokens_neox': 476, 'n_words': 83, 'path': 'NLP/NewsParserLenta.ipynb', 'repo_name': 'omega1996/NewsParser', 'size': '1295'}