我必须从这个网站上提取文章的内容text

from bs4 import BeautifulSoup
import requests
import pandas as pd

url = 'https://economictimes.indiatimes.com/industry/cons-products/food/heinz-braces-up-for-aggressive-marketing/articleshow/5417995.cms'

response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
article = soup.find('article',class_ = 'artData clr paywall')
if article:
    content = article.find('div', class_='artText medium')
    text_contents = content.text.strip() if content else "No data"
else:
    text_contents = "No data"
print(text_contents)

但上面的代码给出了如下所示的输出:

No Data

预期输出:

 'MUMBAI: US foods major Heinz, which owns brands such as Glucon D and Complan in India, has asked the Indian subsidiary to gun for more growth and scout for local acquisitions. It is ramping up investments in R&D and marketing. The aggression is in wake of the double digit growth rates recorded by markets such as India and China which has propelled Heinz’s global sales, said Chris Warmoth, executive vice-president, Asia-Pac, in an ET exclusive. The Rs-900 crore plus Heinz India competes with HUL, Nestle and Glaxo Smithkline. Consumer has intensified the localisation and regionalisation of its brands to cater to specific consumer needs and tastes."We have been dramatically increasing our investment in terms of marketing, building new factory, information systems in India. It is hard not to be extremely upbeat on India. I think we have a very strong organisation and we feel we really know India very well. We have two excellent brands in Complan and Glucon D and we got a lot of proven successes and a great new product pipeline,” said Warmoth. Heinz’s Asia-Pacific division also includes Japan and high-growth emerging markets such as China, India and Indonesia. During fiscal 2009, sales in emerging markets grew by 15.7% propelled by double-digit organic sales growth in these regions. The focus is on leveraging its first-mover advantage and go-to-market capabilities to drive accelerated growth, Warmoth said. After a couple of mistakes such as launching global food brands in a diverse consumer market, Heinz also known for its Heinz ketchup got its act together and focused on a more localised strategy of focusing on specific consumer needs and tastes across Indian markets, strengthened relationships with the customer and trade.Heinz India’s brands like Complan has a market share of 15.7% in the milk drinks segment while Glucon-D has a 62% in the glucose drinks segment with Nycil prickly heat powder at 36.8% and Heinz Ketchup at 2.2 %. Heinz has invested over Rs 300 crore in India since 2007 and is looking at another Rs 100 crore plus investment this year company officials said. Heinz relaunched Complan, launched Complan Nutri Bowl Muesli in TN, Complan Memory and Complan Milk Biscuits in AP with local flavours such as Strawberry and Kesar Badam. The company launched a top-down squeeze pack of Heinz Tomato Ketchup and recently introduced Heinz condiments portfolio with the launch of Heinz Kitchen Klassics, Ready To Eat range which is currently being test marketed in Mumbai. Another key brand from the Heinz portfolio – Glucon-D is available in three flavours – Natural, Orange and more localised Nimbu Paani across the country.“What we found out over the last 6-7 years we have been here is the country being what it is. The food challenges in India are very unique. So every 100 kilometers you drive in this country, the taste preferences change. So, we have learned our lessons and we also know that ketchup is just an entry point. We are looking at other Indian interpretations of ketchups, we are looking at other packaged food, we are looking at other sauces,” said N Thiruambalam, managing director of Heinz India. In 2009, Heinz sales in emerging markets grew 8.8% propelled by sales in India, Indonesia, Latin America and Poland. Emerging markets contribute now 14% of Heinz’s total sales. Heinz is now focusing on building strong operations in fast growing merging markets and stepping up investments in R&D and marketing to drive growth. Emerging markets are expected to contribute about a third of the company’s total global sales growth over the next two years.“We don’t start off necessarily with global brands because I think in food it is much harder to be global than in shampoos or washing detergents or feminine protection or whatever. If you look at lot of the brands we compete within, Glucose category is very Indian and even the flavoured milk segment is very Indian,” said Warmoth.So we start off with more local brands. But in terms of leveraging global scale we are very active. So we have something called the Heinz Marketing Academy, we have something called the Heinz Purchasing Academy, we have something called the Heinz Sales Academy, we have a manufacturing system called the Heinz Global Performance System, which is a standardized set up measures on running factories,"said Warmoth.Heinz is in the middle of a multi year process to roll out a global common information that allows it to start leveraging global scale and have a better view on the commodities when purchasing them.H. J. Heinz Company is a global marketers and producer of healthy, convenient and affordable foods specializing in ketchup, sauces, meals, soups, snacks and infant nutrition. Its leading branded products, including Heinz Ketchup, sauces, soups, beans, pasta and infant foods (representing over one third of Heinz’s total sales), Ore-Ida potato products, Weight Watchers Smart Onesentrees, Boston Marketmeals, T.G.I. Friday’s snacks, and Plasmon infant nutrition.

推荐答案

class_='artText medium'不会 Select 正确的类.

您可以改用:

article.find('div', class_='artText')

输出:

'MUMBAI: US foods major [...] infant nutrition.'

Python相关问答推荐

已安装' owiener ' Python模块,但在导入过程中始终没有名为owiener的模块

从单个列创建多个列并按pandas分组

如何将Matplotlib的fig.add_axes本地坐标与我的坐标关联起来?

有条件地采样我的大型DF的最有效方法

分组数据并删除重复数据

如何在图片中找到这个化学测试条?OpenCV精明边缘检测不会绘制边界框

Pandas 滚动最接近的价值

需要计算60,000个坐标之间的距离

梯度下降:简化要素集的运行时间比原始要素集长

如何让这个星型模式在Python中只使用一个for循环?

如何在表中添加重复的列?

Python列表不会在条件while循环中正确随机化'

合并帧,但不按合并键排序

使用特定值作为引用替换数据框行上的值

try 检索blob名称列表时出现错误填充错误""

Python全局变量递归得到不同的结果

以逻辑方式获取自己的pyproject.toml依赖项

为什么我的sundaram筛这么低效

在Google Drive中获取特定文件夹内的FolderID和文件夹名称

从一个df列提取单词,分配给另一个列