Yerdneass

tryme

May 6th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1.     import requests
  2.     from bs4 import BeautifulSoup
  3.     import csv
  4.    
  5.         def get_html(url):
  6.         r = requests.get(url)    
  7.         r.encoding = 'utf8'
  8.         return r.text  
  9.  
  10.  
  11.     def csv_read(data):
  12.         with open("data.csv", 'header') as file:
  13.             writer = csv.writer(file)
  14.             writer.writerow((data['head'], data['link']))
  15.  
  16.     def get_link(html):
  17.         soup = BeautifulSoup(html, 'lxml')
  18.         head = soup.find('div', id='post').find_all('header', class_="post-header-title")
  19.         for i in head:
  20.             link = 'https://point.md/ru/novosti' + i.get('href')
  21.             heads= i.find('h1').string
  22.             data = {'head': heads,
  23.                     'link': link}
  24.             csv_read(data)
  25.  
  26.  
  27.     data = get_link(get_html('https://point.md/ru/novosti'))
Add Comment
Please, Sign In to add comment