Reputation: 9705
Below in the grayed out area is some text that I am trying to extract in a page.
I dont know how to access the text in the gray area. I tried the following but it did not work. The class does not have an id - how to get the text inside it?
comment = soup.find("div", {"class", "GCARQJCDEXD"})
Upvotes: 1
Views: 40
Reputation: 474071
You can locate the element by matching a class
attribute to an empty string:
from bs4 import BeautifulSoup
data = """
<div class="GCARQJCDEXD">
<div class="clearfix hidden">something here</div>
<div class>
desired text
</div>
</div>
"""
soup = BeautifulSoup(data, "html.parser")
comment = soup.find("div", {"class": "GCARQJCDEXD"}).find("div", {"class": ""})
print(comment.get_text(strip=True))
Prints desired text
.
Upvotes: 1