I have a problem with text scraping problem. The website that I am scraping has 3 same line of html but 3 different informations. Like this
'<div class="section">...</div>'
'<div class="section">...</div>'
'<div class="section">...</div>'
So I got the texts from first <div class="section">...</div>
using this code 'soup.find("div", class_="section").text.strip()'
But cant scrape texts from 2nd and 3rd <div class="section">...</div>
. Help me pls.
/Ps: New to web scraping and also english is my second language if I were not clear on writing./
2
Answers
divs = soup.find("div", class_="section")
this part selects a list of divs, even if there’s only one, and you can then select each one individually. but if you add
.text
it will instead mash all divs text into one blob. so just keep the list and access its members like so:You can use
find_all
method ofsoup
. I will provide sample code.Using
find
will only select the first div withclass="section"
, but usingfind_all
will select all divs withclass="section"
and extract the text information inside the divs.