Hack Forums
[Python] beautiful soup catch this - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] beautiful soup catch this (/showthread.php?tid=6067883)



beautiful soup catch this - SIM-1866423 - Apr 16, 2020

After many years first time i need help on scraping my brain unfunctional right now 🤮

[Image: 2W8xtUU.png]


Code
<body contenteditable="true" dir="ltr" class="">

<div>text text</div>
<div>text text</div>
<div>text text</div>
<div>text text</div>
<div>text text</div>

</body>


How can i get inside text from this.


RE: beautiful soup catch this - 4Txe4y33C9zvNhMj - Apr 16, 2020

If you're trying to get the "SOMETHING SOMETHING SOMETHING" text (clarify please):

Code
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')

result = soup.find('body')



RE: beautiful soup catch this - SIM-1866423 - Apr 16, 2020

(Apr 16, 2020 04:00 PM)4Txe4y33C9zvNhMj Wrote:  If you're trying to get the "SOMETHING SOMETHING SOMETHING" text (clarify please):

Code
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')

result = soup.find('body')

yeap sorry you are right i just update question, all div tags.


RE: beautiful soup catch this - 4Txe4y33C9zvNhMj - Apr 16, 2020

(Apr 16, 2020 04:29 PM)SIM-1866423 Wrote:  yeap sorry you are right i just update question, all div tags.

Updated:

Code
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)

for div in soup.find_all("div"):
  print("content: {}".format(div.text))



RE: beautiful soup catch this - SIM-1866423 - Apr 16, 2020

(Apr 16, 2020 04:49 PM)4Txe4y33C9zvNhMj Wrote:  Updated:

Code
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)

for div in soup.find_all("div"):
 print("content: {}".format(div.text))

Thats not helping unfortunately.Thats why im asking, i just need div tags inside of this specific body tags.There a lot of div tags at outside of this body tags ..


RE: beautiful soup catch this - 4Txe4y33C9zvNhMj - Apr 16, 2020

(Apr 16, 2020 04:56 PM)SIM-1866423 Wrote:  Thats not helping unfortunately.Thats why im asking, i just need div tags inside of this specific body tags.There a lot of div tags at outside of this body tags ..

Could you elaborate?

You're trying to select all div tags in the body that have what feature?


RE: beautiful soup catch this - SIM-1866423 - Apr 16, 2020

(Apr 16, 2020 05:02 PM)4Txe4y33C9zvNhMj Wrote:  Could you elaborate?

You're trying to select all div tags in the body that have what feature?


No feature or anything table exact same in first post.


RE: beautiful soup catch this - Nachfolger - Apr 16, 2020

(Apr 16, 2020 05:05 PM)SIM-1866423 Wrote:  No feature or anything table exact same in first post.
You want to select the text from all the divs within the body element, correct? You're being so incredibly vague in every single post. Learn how to express your thoughts clearly.


RE: beautiful soup catch this - SIM-1866423 - Apr 16, 2020

(Apr 16, 2020 05:09 PM)Nachfolger Wrote:  You want to select the text from all the divs within the body element, correct? You're being so incredibly vague in every single post. Learn how to express your thoughts clearly.


[Image: KXoah7n.png]


I have literally 0 idea how this ambiguous but fine.


RE: beautiful soup catch this - Nachfolger - Apr 16, 2020

(Apr 16, 2020 05:21 PM)SIM-1866423 Wrote:  [Image: KXoah7n.png]


I have literally 0 idea how this ambiguous but fine.
You just need the text from each div? You said that outside of the body there are div tags, and you want to ignore them, but the screenshot you provided (in OP) has no divs outside of the body.

1. All divs in the screenshot are IN THE BODY
2. The code provided earlier pulls the text from inside each div

Again, I'm not seeing an issue.