-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterfax_parser.py
38 lines (33 loc) · 1.12 KB
/
interfax_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from bs4 import BeautifulSoup as web
from basic_parser import Parser
class Interfax_parser(Parser):
def __init__(self):
super().__init__("http://www.interfax.ru/rss.asp")
self.site_encoding = "windows-1251"
def grab(self, url):
content = web(self.get_content(url, self.site_encoding), "html.parser")
obj = {}
if content.select(".textMTitle")[0]:
obj["title"] = content.select(".textMTitle")[0].text
if content.select(".inner > img"):
obj["image"] = "{}{}".format(
"https://www.interfax.ru/",
content.select(".inner > img")[0]["src"]
)
print(len(content.select(".at > article > p")))
if content.select(".at > article > p"):
obj["content"] = list(
map(
lambda x: x.text,
content.select(".at > article > p")
)
)
return obj
if __name__ == "__main__":
inter = Interfax_parser()
news = inter.news()
print(news)
url = news[0]["link"]
print(url)
data = inter.grab(url)
print(data)