Код: Выделить всё
[img]http://i4.manchestereveningnews.co.uk/incoming/article13390833.ece/ALTERNATES/s615/Mike-Grimshaw-34-was-fatally-attacked-following-the-attack-outside-his-Trafford-home-last-Thursday.jpg[/img]
Код: Выделить всё
import bs4 as bs
import urllib.request
import datetime
import random
import re
random.seed(datetime.datetime.now())
sauce = urllib.request.urlopen('http://www.manchestereveningnews.co.uk/news/greater-manchester-news').read()
soup = bs.BeautifulSoup(sauce, 'lxml')
#
title = soup.title
link = soup.link
image = re.search(img 'srcset=img(.*?),)
#this doesnt work, not sure how to
strong = soup.strong
description = soup.description
location = soup.location
title = soup.find('h1', class_ ='publication-font', )
image = soup.find('img')
strong = soup.find('strong')
location = soup.find('em').find('a')
description = soup.find('div', class_='description',to.text)
#Previous Code
print("H1:", title.text)
print("Article Link:", link)
print("Image Url:\n", image)
print("1st Paragraph:\n", strong.text)
print("2nd Paragraph:\n", description.string)
print("Location:\n", location.text)
Код: Выделить всё
Greater Manchester News
Family of dad stabbed in the neck while defendin
g his fiancée from thugs speak of their heartbreak
Mike Grimshaw, 34, died after being stabbed in the neck outside his
home in Trafford last Thursday
Trafford
Будем очень признательны за любые идеи.
Подробнее здесь: https://stackoverflow.com/questions/453 ... image-name