Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Задача 3 (2 балла)
- def any_news_about_harry(url):
- import urllib.request
- try:
- f = urllib.request.urlopen(url)
- if "Harry" in str(f.read()):
- return True
- else:
- return False
- except:
- False
- Задача 2 (1 балл)
- def get_strong(html):
- import bs4
- soup = bs4.BeautifulSoup(html, "html.parser")
- return soup.strong.text
- Задача 3 (1 балл)
- def all_images_src(xml):
- import bs4
- soup = bs4.BeautifulSoup(xml, "html.parser")
- res = []
- for a in soup.find_all(['img']):
- res.append(a['src'])
- return res
- Задача 4 (2 балла)
- from urllib.parse import urlencode
- entrypoint = "https://ru.wikipedia.org/w/index.php?"
- def mkurl(title, oldid):
- return entrypoint+urlencode(dict(title=title, oldid=oldid))
- def get_all_headings(url):
- import bs4
- import urllib.request
- res = []
- try:
- f = urllib.request.urlopen(url)
- soup = bs4.BeautifulSoup(f.read(), "html.parser")
- s = None
- for a in soup.find_all(['span'], {'class': 'mw-headline'}):
- if 'h2'in str(a.parent):
- res.append(a.parent.find(['span'], {'class': 'mw-headline'}).text)
- return res
- except:
- return ["Not found"]
- Задача 5 (3 балла)
- from urllib.parse import urlencode
- entrypoint = "https://ru.wikipedia.org/w/index.php?"
- def mkurl(title):
- return entrypoint+urlencode(dict(title=title))
- def city_site(name):
- url = mkurl(name)
- import bs4
- import urllib.request
- try:
- f = urllib.request.urlopen(url)
- soup = bs4.BeautifulSoup(f.read(), "html.parser")
- for a in soup.find_all(['tr']):
- buferVar = a.find('th')
- if buferVar != None and buferVar.text == "Официальный сайт":
- return a.find(['a'], {'class': 'external text'})['href']
- except:
- return None
- Задача 6 (4 балла)
- def get_languages_hse(last_name):
- def get_teacher_url(last_name):
- url = 'https://www.hse.ru/org/hse/ouk/hmat/persons'
- import bs4
- import urllib.request
- try:
- f = urllib.request.urlopen(url)
- soup = bs4.BeautifulSoup(f.read(), "html.parser")
- s = None
- for a in soup.find_all(['a'], {'class': 'fa-person__name'}):
- if last_name in a.text:
- return 'http://' + a['href'][2:]
- except:
- return None
- # coding=utf8
- url = get_teacher_url(last_name)
- import bs4
- import urllib.request
- res = []
- try:
- f = urllib.request.urlopen(url)
- soup = bs4.BeautifulSoup(f.read(), "html.parser")
- for a in soup.find_all(['dl'],{'class':'main-list large main-list-language-knowledge-level'}):
- for r in a.find_all('dd'):
- res.append(r.text)
- return res
- except:
- pass
Add Comment
Please, Sign In to add comment