Home python python, bs4 how to extract text between tags

python, bs4 how to extract text between tags

Author

Date

Category

The task is to obtain text between the tags & lt; div class = "_ profile_online profile_online" & gt; & lt; div class = "profile_online_lv" & gt; and & lt; b class = "mob_onl profile_mob_onl "OnClick =" MobilePromo (); " onmouseover = "MobileOnLinetip (this, {MID: CUR.OID, RIGHT: 1, WAS: 1})" & gt; & lt; / b & gt; & lt; / div & gt; & lt; / div & gt; ',' html.parser ')

(Need Find Text Between Tags)

import bs4
From BS4 Import Beautifulsoup
Import Selenium.
From Selenium Import WebDriver
Driver = WebDriver.chrome ('D: \ chromedriver.exe')
Driver.get ('View-Source: https: //vk.com/id5')
soup = bs4.BeautifulSoup ( '& lt; div class = "_ profile_online profile_online" & gt; & lt; div class = "profile_online_lv" & gt; online & lt; b class = "mob_onl profile_mob_onl" onclick = "mobilePromo ();" onmouseover = "mobileOnlineTip ( This, {MID: CUR.OID, RIGHT: 1, WAS: 1}) "& gt; & lt; / b & gt; & lt; / div & gt; & lt; / div & gt; ',' html.parser ')
Print (Soup.div.Text)

But the point is that I prescribe in a pemarly Soup manually that in the tag online and I need to get a value between the tags that can vary


Answer 1

Of course, you do not need to trim. You connected beautifulsoup, but do not use it at all. Explore the article

from bs4 import beautifulsoup
Soup = Beautifulsoup ('& lt; div class = "_ profile_online profile_online" & gt; & lt; div class = "profile_online_lv" & gt; online & lt; b class = "mob_onl profile_mob_onl" onClick = "MobilePromo ();" OnmouseOver = "MobileOnLinetip (this, {MID: CUR.OID, RIGHT: 1, WAS: 1}) "& gt; & lt; / b & gt; & lt; / div & gt; & lt; / div & gt; ',' html.parser ')
Print (Soup.div.div.text)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions