Я довольно новичок в программировании. Но мне нужна только новостная статья, есть ли простой способ удалить ненужный HTML из текста, так как мне нужно дополнительно перебрать несколько ссылок, а затем выполнить анализ настроений над ними.
p = 'https://www.moneycontrol.com/news/business/earnings/cadila-health-consolidated-december-2018-net-sales-at-rs-3577-90-crore-up-9-77-y-o-y-3497711.html'
html = requests.get(p)
soup1 = BeautifulSoup(html.text,'html.parser')
date = soup1.find_all("div", {"class":"arttidate"})
print(date)
article = soup1.find_all("script", {"class":"arti-flow"})
print(article)
Выходные данные следующие
[ < div class = "arttidate " > Last Updated: Feb 07, 2019 03: 05 PM IST | Source: < span > Moneycontrol.com < /span></div > ]
[ < div class = "arti-flow"
id = "article-main" >
<!-- .CONTENT BODY -->
<
p > < div class = "top_dis"
id = "div_app_container" > < b > Reported Consolidated quarterly numbers
for Cadila Healthcare are: < /b></div > < /p><p>Net Sales at Rs 3,577.90 crore in December 2018 up 9.77% from Rs. 3,259.60 crore in December 2017.</p > < p > Quarterly Net Profit at Rs.510.70 crore in December 2018 down 6 % from Rs.543.30 crore in December 2017. < /p><div class="ads-320-250 show-moblie mid-arti-ad"><div id="Moneycontrol_Mobile_WAP/MC_WAP_News / MC_WAP_News_Internal_300x250_Middle_2 "> <
script type = "text/javascript" >
var width = window.innerWidth || document.documentElement.clientWidth;
adKey = "Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_300x250_Middle_2";
if (width >= 768 && adKey.indexOf("Moneycontrol") != -1 && adKey.indexOf("Moneycontrol_Mobile_WAP") < 0) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_300x250_Middle_2")
});
}
if (width <= 768 && adKey.indexOf("Moneycontrol_Mobile_WAP") != -1) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_300x250_Middle_2")
});
}
<
/script> <
/div></div > < div class = "hide-moblie mid-arti-ad" > < div id = "Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_OutStream" >
<
script type = "text/javascript" >
var width = window.innerWidth || document.documentElement.clientWidth;
adKey = "Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_OutStream";
if (width >= 768 && adKey.indexOf("Moneycontrol") != -1 && adKey.indexOf("Moneycontrol_Mobile_WAP") < 0) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_OutStream")
});
}
if (width <= 768 && adKey.indexOf("Moneycontrol_Mobile_WAP") != -1) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol_Mobile_WAP/MC_WAP_News/MC_WAP_News_Internal_OutStream")
});
}
<
/script> <
/div></div > < script >
date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
$.cookie("dfp_cookie_article", "Y1", {
expires: date,
path: "/",
domain: ".moneycontrol.com"
}); < /script><p>EBITDA stands at Rs. 870.90 crore in December 2018 down 1.29% from Rs. 882.30 crore in December 2017.</p > < div class = "hide-moblie mid-arti-ad" > < div id = "Moneycontrol/MC_News/MC_News_Internal_Article_Native" >
<
script type = "text/javascript" >
var width = window.innerWidth || document.documentElement.clientWidth;
adKey = "Moneycontrol/MC_News/MC_News_Internal_Article_Native";
if (width >= 768 && adKey.indexOf("Moneycontrol") != -1 && adKey.indexOf("Moneycontrol_Mobile_WAP") < 0) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol/MC_News/MC_News_Internal_Article_Native")
});
}
if (width <= 768 && adKey.indexOf("Moneycontrol_Mobile_WAP") != -1) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol/MC_News/MC_News_Internal_Article_Native")
});
}
<
/script> <
/div></div > < div class = "hide-moblie mid-arti-ad" > < div id = "Moneycontrol/MC_News/MC_News_Internal_OutStream" >
<
script type = "text/javascript" >
var width = window.innerWidth || document.documentElement.clientWidth;
adKey = "Moneycontrol/MC_News/MC_News_Internal_OutStream";
if (width >= 768 && adKey.indexOf("Moneycontrol") != -1 && adKey.indexOf("Moneycontrol_Mobile_WAP") < 0) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol/MC_News/MC_News_Internal_OutStream")
});
}
if (width <= 768 && adKey.indexOf("Moneycontrol_Mobile_WAP") != -1) {
googletag.cmd.push(function() {
googletag.display("Moneycontrol/MC_News/MC_News_Internal_OutStream")
});
}
<
/script> <
/div></div > < script >
date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
$.cookie("dfp_cookie_article", "Y1", {
expires: date,
path: "/",
domain: ".moneycontrol.com"
}); < /script><p>Cadila Health EPS has decreased to Rs. 4.99 in December 2018 from Rs. 5.31 in December 2017.</p > < p > Cadila Health shares closed at 317.95 on February 06, 2019(NSE) and has given - 16.39 % returns over the last 6 months and - 21.40 % over the last 12 months. < /p></div >
]
Фактический желаемый результат будет: - Чистый объем продаж на уровне 3 577,90 крор в декабре 2018 года по сравнению с 9,77% по сравнению с рупиями.3 259,60 крор в декабре 2017 года.
Квартальная чистая прибыль в рупиях.510,70 крор в декабре 2018 года снизился на 6% по сравнению с рупиями.543,30 крор в декабре 2017 года. EBITDA составляет Rs.870,90 крор в декабре 2018 года снизился на 1,29% от рупий.882,30 крор в декабре 2017 года. Cadila Health EPS снизился до рупий.4.99 в декабре 2018 от рупий5,31 в декабре 2017 года.
Акции Cadila Health закрылись на 317,95 6 февраля 2019 года (NSE) и дали -16,39% прибыли за последние 6 месяцев и -21,40% за последние 12 месяцев.
Редактировать: во время написания этого вывода я понял, что все новости, которые мне нужны, содержатся в тегах "p", поэтому мне нужно было бы перехватить новостную статью в другой объект и прочитать только теги "p", может кто-нибудь мне помочькто я могу пойти делать это?