java - 如何从html仅获取没有垃圾的文本?

标签 java html html-parsing jsoup

我正在使用jsoup尝试仅获取用于研究的文本,并且文本包含很多“垃圾”,而且我不知道如何摆脱它。
我的代码:

Document doc = Jsoup.connect(link).userAgent("Mozilla").ignoreHttpErrors(true).timeout(0).get();

String plainText = doc.body().text();


该网站的网址(保存在上面的代码中的变量链接中)例如:
http://www.besthealthmag.ca/best-eats/healthy-eating/5-reasons-to-eat-more-avocados/

输出将是:

加拿大最佳健康杂志活得更好。感觉很棒最好的外观美容指甲的皮肤样式最好的感冒和流感糖尿病健康心脏健康口腔健康关系睡眠健康最好吃烹饪饮食消化健康饮食营养食谱冰沙掉落竞赛和游戏竞赛游戏优惠券订阅赠送礼物您在这里:主页/最佳饮食/健康饮食/吃更多鳄梨的5个理由吃鳄梨的5个理由忘记fat'avocados是一种超级健康的方法,可以在饮食中添加有价值的营养物质和纤维(是的,还有健康的脂肪!)。这就是“最佳健康”的原因有些人在尝试提高健康意识时,避免食用鳄梨,因为这些水果的脂肪和卡路里含量相对较高(一半的中等鳄梨中含138卡路里和14.1克脂肪)。然而,鳄梨是您可以吃的最好的食物之一,富含营养成分和有益心脏健康的化合物。定期食用它们的五个主要理由。 1.鳄梨富含类胡萝卜素鳄梨是叶黄素的重要来源,叶黄素是一种抗氧化剂,有助于预防眼疾。它们还含有相关的类胡萝卜素玉米黄质,α-胡萝卜素和β-胡萝卜素,以及生育酚(维生素E)。但是鳄梨本身不仅是类胡萝卜素的丰富来源,而且还可以帮助您从其他食物中获取更多的这些营养素。类胡萝卜素是亲脂性的(溶于脂肪,而不是水),因此,食用富含类胡萝卜素的食物,例如水果和蔬菜,以及富含单不饱和脂肪的鳄梨,可以帮助您的身体吸收类胡萝卜素。一种简单的方法是将鳄梨切片加到混合沙拉中。 2.鳄梨使您感到饱饱一半鳄梨含有3.4克纤维,包括可溶和不溶纤维,这两种物质都需要您的身体保持消化系统平稳运转。此外,可溶性纤维可减缓体内碳水化合物的分解,帮助您长时间保持饱腹感。鳄梨还含有油酸,这种脂肪会激活大脑的一部分,使您感到饱饱。与加工食品中发现的不健康的饱和脂肪和反式脂肪相比,更健康的含油酸不饱和脂肪已显示出更高的饱腹感。 3.鳄梨可以保护未出生的婴儿和您的心脏一杯鳄梨可提供建议的每日叶酸摄入量的近四分之一,叶酸是一种维生素,可降低出生缺陷的风险。如果您怀孕或打算成为“ avocados”,将有助于保护未出生的婴儿。叶酸摄入量高还可以降低心脏病发作和心脏病的风险。您的家人有心脏病史吗,或者您有心脏病的危险因素(例如超重或吸烟)?鳄梨可以帮助您保持心脏健康。 4.鳄梨可以帮助降低胆固醇除了增加饱腹感外,鳄梨中的油酸还可以帮助降低胆固醇水平。在一项研究中,食用富含鳄梨的饮食的人的总胆固醇水平显着降低,包括LDL胆固醇降低。他们的HDL胆固醇(健康型)水平增加了11%。高胆固醇是心脏病的主要危险因素之一。鳄梨的降胆固醇特性及其叶酸含量有助于保持心脏健康。 5.鳄梨味道很好最后一个原因是简单的“ avocados”是增加餐食风味和质地的健康方法。在沙拉或一碗汤上扔切碎的鳄梨,将鳄梨酱作为开胃菜或调味品,或者尝试以下健康的鳄梨食谱之一,以使饮食中的鳄梨更健康。 ‘牛油果和鸡肉俱乐部三明治’牛油果和虾杯’牛油果薄片配野生蓝莓奶酪混合‘烤三文鱼配牛油果芒果莎莎酱’经典鳄梨酱千万不要错过!订阅我们的免费每周新闻通讯,获取营养食谱,健康的减肥秘诀,​​保持身材的简便方法以及所有需要的健康新闻,这些信息会直接发送到您的收件箱。提起下:健康饮食标签:饮食与营养保持健康和快乐脊椎伸展的秘诀资料来源:最佳健康杂志,2011年夏季; Kagan McLeod的插图谁不想要更好的姿势?快速移动可以使您轻松地站立(和坐姿),因为它使脊椎对齐。 Margot说,它可以缓解臀部和肩膀的紧张……[阅读更多...]带有花园蔬菜的烤牛肉资料来源:Cook Smart for a Heart Heart,加拿大读者文摘成分2瓣大蒜,切碎1到2茶匙胡椒粉1骨牛肉沙朗牛排2厘米厚,约1.2千克500克土豆,四分之一500克绿豆1大红洋葱,非常... [阅读全文...]热带水果冰沙配料1/4杯(60毫升)新鲜或罐装菠萝块1/4杯(60杯)毫升)新鲜芒果块2颗新鲜或冷冻的草莓,去壳1杯(250毫升)低脂豆浆1汤匙(15毫升)柠檬汁混合至光滑。每份可食用。[…阅读更多...]美味的迷迭香“ “最佳健康杂志,2012年3月/ 4月; 1杯(250毫升)全麦面粉1杯(250毫升)通用面粉1 1/2茶匙(7毫升)干迷迭香(或1汤匙/ 15毫升新鲜切碎)1茶匙(5毫升)发酵粉1茶匙(5毫升)磨碎…[阅读更多...]菜肉馅煎蛋饼和芦笋和葱油成分1磅新鲜的薄芦笋长矛4盎司熏火腿或培根,厚片,脂肪充足(约4片)1/2磅葱3汤匙初榨3汤匙橄榄油1/2茶匙粗海盐或犹太盐,或更多口味8 [更多...]我们还认为您会喜欢:凯特琳·布里斯托(Kaitlyn Bristowe)谈大头发,碧昂斯(Beyonc)?以及肉毒杆菌毒素,填充剂和一般皮肤护理:在Book肿之前要知道些什么?如何知道是否患有肠易激综合症,如果没人相信您生病了该怎么办? #PhysiotherapyHelpsLives:中风恢复在社交网络上关注我们? ? ? ? ? ?特色内容5种减轻背部疼痛的方法遭受背痛吗?我们深入研究了最新的研究,以发现您可以采取哪些措施来缓解背部疼痛Willow:一种用于疼痛食品和肌肉和关节疼痛的补品的自然疗法,影响加拿大人的5种自身免疫性疾病。 3)奖品包!赢取牙买加旅行假期输入机会赢得牙买加旅行!载入thickbox ...关于最佳健康最佳健康是由著名出版商《读者文摘》(Reader's Digest)撰写的健康与健康杂志,为当今的加拿大当代女性带来鼓舞人心的声音。单击此处了解广告机会。您的隐私权|客户服务|订阅|凯特琳·布里斯托(Kaitlyn Bristowe)谈论大头发,碧昂斯(Beyonc)?以及肉毒杆菌毒素,填充剂和一般皮肤护理:在Book肿之前要知道些什么?如何知道是否患有肠易激综合症,如果没人相信您生病了该怎么办? #PhysiotherapyHelpsLives:中风恢复不要错过最佳健康的一天注册我们的新闻通讯与我们建立社会联系? ? ? ? ? ?显示完整网站版权所有©2016 The Reader's Digest Association,Inc.

有很多垃圾:问号,以及[阅读更多...]和更多。

我该怎么办?

最佳答案

您可以使用扫描仪并跳过不喜欢的令牌。像这样遍历令牌

Scanner s = new Scanner(": Best Health Magazine Canada Live Better. Feel Great Best Looks Beauty Hair Nails Skin Style Best You Cold and Flu Diabetes Health Heart Health Oral Health Relationships Sleep Wellness Best Eats Cooking Diet Digestion Healthy Eating Nutrition Recipes Smoothies Swap and Drop Contests and Games Contests Games Coupons Subscribe Give a gift You are here : Home / Best Eats / Healthy Eating / 5 reasons to eat more avocados 5 reasons to eat more avocados Forget the fat'avocados are a super-healthy way to add valuable nutrients and fibre (yes, and healthy fat!) to your diet. Here's why By Best Health Some people, in their attempts to be health-conscious, avoid avocados due to the relatively high fat and calorie content of these fruits (138 calories and 14.1g fat in half a medium-sized avocado). Yet avocados are one of the best foods you can eat, packed with nutrients and heart-healthy compounds. Here are five great reasons to eat them regularly. 1. Avocados are packed with carotenoids Avocados are a great source of lutein, a carotenoid that works as an antioxidant and helps protect against eye disease. They also contain the related carotenoids zeaxanthin, alpha-carotene and beta-carotene, as well as tocopherol (vitamin E). But avocados aren’t just a rich source of carotenoids by themselves’they also help you get more of these nutrients from other foods. Carotenoids are lipophilic (soluble in fat, not water), so eating carotenoid-packed foods like fruits and vegetables along with monounsaturated-fat-rich avocados helps your body absorb the carotenoids. An easy way to do this is to add sliced avocado to a mixed salad. 2. Avocados make you feel full Half an avocado contains 3.4 grams of fibre, including soluble and insoluble, both of which your body needs to keep the digestive system running smoothly. Plus, soluble fibre slows the breakdown of carbohydrates in your body, helping you feel full for longer. Avocados also contain oleic acid, a fat that activates the part of your brain that makes you feel full. Healthier unsaturated fats containing oleic acid have been shown to produce a greater feeling of satiety than less-healthy saturated fats and trans fats found in processed foods. 3. Avocados can protect your unborn baby’and your heart One cup of avocado provides almost a quarter of your recommended daily intake of folate, a vitamin which cuts the risk of birth defects. If you’re pregnant’or planning to be’avocados will help protect your unborn baby. A high folate intake is also associated with a lower risk of heart attacks and heart disease. Does your family have a history of heart problems, or do you have risk factors (such as being overweight or smoking) for heart disease? Avocados could help keep your heart healthy. 4. Avocados can help lower your cholesterol As well as increasing feelings of fullness, the oleic acid in avocados can help reduce cholesterol levels. In one study, individuals eating an avocado-rich diet had a significant decrease in total cholesterol levels, including a decrease in LDL cholesterol. Their levels of HDL cholesterol (the healthy type) increased by 11%. High cholesterol is one of the main risk factors for heart disease. The cholesterol-lowering properties of avocado, along with its folate content, help keep your heart healthy. 5. Avocados taste great The last reason is simple’avocados are a healthy way to boost the flavour and texture of your meals. Toss chopped avocado on a salad or bowl of soup, serve guacamole as an appetizer or condiment, or try one of these healthy avocado recipes to get more healthy avocado into your diet. ‘ Avocado and Chicken Club Sandwich ‘ Avocado and Shrimp Cups ‘ Avocado Carpaccio with Wild Blueberry Cottage Cheese Mix ‘ Broiled Salmon with Avocado-Mango Salsa ‘ Classic Guacamole Don’t miss out! Sign up for our free weekly newsletters and get nutritious recipes, healthy weight-loss tips, easy ways to stay in shape and all the health news you need, delivered straight to your inbox. Filed Under: Healthy Eating Tagged With: Diet & Nutrition Secrets to Staying Healthy & Happy Spine stretch Source: Best Health Magazine, Summer 2011; Illustration by Kagan McLeodWho doesn't want better posture? This quick move can help you stand (and sit) tall with ease, as it aligns the spine. It can relieve tension in the hips and shoulders, says Margot … [Read More...] Seared Beef with Garden Vegetables Source: Cook Smart for a Healthy Heart, Reader's Digest CanadaIngredients2 garlic cloves, finely chopped1?2 teaspoon pepper1 bone-in beef sirloin steak 2 cm thick, about 1.2 kg500 g potatoes, quartered500 g green beans1 large red onion, very … [Read More...] Tropical Fruit Smoothie Ingredients1/4 cup (60 mL) fresh or canned pineapple chunks1/4 cup (60 mL) fresh mango chunks2 fresh or frozen strawberries, hulled1 cup (250 mL) plain low-fat soy milk1 Tbsp (15 mL) lime juiceDirections Blend until smooth.Serves one.Nutritions Per … [Read More...] Savoury Rosemary Squaffles Best Health Magazine, March/April 2012; Photo by Michael AlberstatIngredients1 cup (250 mL) whole-wheat flour1 cup (250 mL) all-purpose flour1 1/2 tsp (7 mL) dried rosemary (or 1 Tbsp/15 mL chopped fresh)1 tsp (5 mL) baking powder1 tsp (5 mL) grated … [Read More...] Frittata with Asparagus and Scallions Ingredients1 pound fresh, thin asparagus spears4 ounces prosciutto or bacon, thick slices with ample fat (about 4 slices)1/2 pound scallions3 tablespoons extra-virgin olive oil1/2 teaspoon coarse sea salt or kosher salt, or more to taste8 large … [Read More...] We Also Think You’ll Like: Kaitlyn Bristowe Talks Big Hair, Beyonc? and The Bachelor Botox, Fillers and General Skin Treatments: What to Know Before You Book Bloated? How to Know if it’s Irritable Bowel Syndrome What If No One Believed You Were Sick? #PhysiotherapyHelpsLives: Stroke Recovery Follow us on Social Networks ? ? ? ? ? ? Featured Content 5 ways to relieve back pain Suffering from an aching back? We dug into the latest research to find out what you can do to help relieve back pain Willow: A Natural Remedy for Pain Foods and Supplements to Ease Muscle and Joint Pain 5 autoimmune diseases affecting Canadians CONTESTS Best for Last Enter to win one of three (3) Prize Packs! Win A Holiday to Jamaica Enter for a chance to win a trip to Jamaica! Load thickbox... ABOUT BEST HEALTH Best Health is a health & wellness magazine from renowned publisher Reader’s Digest that brings an inspiring voice to today’s contemporary Canadian woman. Click here to learn about advertising opportunities. Your Privacy Rights | Customer Care | Subscribe | Sitemap Recent Posts Kaitlyn Bristowe Talks Big Hair, Beyonc? and The Bachelor Botox, Fillers and General Skin Treatments: What to Know Before You Book Bloated? How to Know if it’s Irritable Bowel Syndrome What If No One Believed You Were Sick? #PhysiotherapyHelpsLives: Stroke Recovery Don't miss a day of Best Health Sign up for our newsletters CONNECT WITH US ON SOCIAL ? ? ? ? ? ? Show Full Site Copyright © 2016 The Reader's Digest Association, Inc.");
StringBuilder nogarbage = new StringBuilder();
StringBuilder trashbin  = new StringBuilder();
StringBuilder receiver  = null;
while (s.hasNext())
{
    String token = s.next();

    if (isGood(token))        //implement isGood somewhere
    {
        receiver = nogarbage;
    }
    else
    {
        receiver = trash;
    }
    receiver.append(token);
}
System.out.println(nogarbage);
System.out.println("Trashbin contents "+trashbin);

关于java - 如何从html仅获取没有垃圾的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36032484/

相关文章:

php - 从硬编码HTML站点中删除index.php

java - 循环群生成器

java - 无法创建文件并断言其存在

java - 如何在Spring Tool Suite中运行两个Web项目而不发生冲突?

java - 从 URL 连接 Java 读取

python - 从HTML内容获取社交网络信息

python - 用于 HTML 解析的最佳 Python 模块

java - 无法使用 SimpleDateFormat 解析德语星期几缩写

java - Selenium java无法获取html文本

javascript - 没有 onclick for button, div, img with IE 9