This is the first post. Thank you.
I'm trying to scrape my own site. Data fetched
<div class="st-kaiwa-hukidashi">Target character string</div>
<div class="st-kaiwa-hukidashi2">Target character string</div>
I want to keep only the "target character string" of.
Therefore,
for num in ["", "2"]:
kaiwa = "div.st-kaiwa-hukidashi{}" .format(num)
talk = soup.select(kaiwa)
for s in talk :
trash = "<div class={}>".format(kaiwa)
t = s.text.replace("trash" , '')
print(t)
When I executed, I was able to extract only the "target character string" cleanly.
In this code,
<div class="st-kaiwa-hukidashi">
<div class="st-kaiwa-hukidashi2">
I was planning to remove only
</div>
It looks like it has been replaced.
I'm sorry to ask you a rudimentary question, but I would like you to teach me why __ Why is it replaced with'' to </ div> __.
Thank you.
Recommended Posts