html - get content of <li> tags with beautifulsoup in python -


i want content of first 3 <li> tag after <section> tag, don't know how manipulate children tag in beautifulsoap, tried strip text , want splitting wasn't successful.

this html code :

<section class="l-map">                                     <ul>                                         <li>خیابان شریعتی، روبروی پارک کوروش، کوچه پیروز، پلاک 48 </li>                                         <li>22855157 22852085</li>                                         <li>شریعتی:قلهک، سید خندان                                      </li>                                     </ul>                                     <div class="foot">                                         <a class="dm fancy" href="#contact" id="inline">پیام مستقیم به مدیر</a>                                         <a class="rm" href="#phonenumber" id="inline">دریافت پیامکی اطلاعات</a>                                     </div>                                     <input id="ismaximumsmsreached" name="ismaximumsmsreached" value="false" type="hidden">                                     <div style="display:none">                                         <div id="phonenumber">                                             <div class="contact-form number">                                                 <h1>                                                     دریافت پیامکی اطلاعات                                                     <i class="icon contact"></i>                                                 </h1>                                                 <p>                                                     شماره تلفن همراه خود را وارد کنید.                                                 </p>                                                 <form id="sendsms">                                                     <div class="form-input">                                                         <input id="cellphone" name="cellphone" placeholder="برای مثال. 09121112222" type="text">                                                       </div>                                                     <div class="form-submit">                                                         <button type="submit" href="#" class="submit">ارسال</button>                                                     </div>                                                     <p class="alert-box"></p>                                                 </form>                                             </div>                                         </div>                                     </div>                                     <div style="display:none">                                         <div id="contact">                                             <div class="contact-form">                                                 <h1>                                                     ارسال پیام به مدیریت رستوران                                                     <i class="icon message"></i>                                                 </h1>                                                 <p>                                                     در این بخش شما می توانید به صورت مستقیم به مدیریت رستوران پیام ارسال نمایید.                                                     <br>                                                     پیام خود را در زیر بنویسید و ارسال نمایید.                                                 </p>                                                 <form id="managermessage">                                                     <div class="form-input">                                                         <input id="messagesendername" name="messagesendername" placeholder="نام شما (اختیاری)">                                                          <input id="messagesenderphone" name="messagesenderphone" placeholder="تلفن تماس شما (اختیاری)"><br>                                                         <input id="messagesenderemail" name="messagesenderemail" placeholder="ایمیل شما (اختیاری)"><br>                                                         <textarea id="messagetomanager" name="messagetomanager" placeholder="پیام"></textarea>                                                     </div>                                                     <div class="form-submit">                                                         <button type="submit" href="#" class="submit">ارسال</button>                                                     </div>                                                     <p class="alert-box"></p>                                                 </form>                                             </div>                                         </div>                                     </div>                                 </section> 

i can access whole <section> tag line of code:

address = soup.find('section', class_="l-map") 

i appreciate every or comment give me :)

you can use function .find_all() find li components inside section , , text using either .text attribute or method - .get_text() . example -

>>> lis in address.find_all('li'): ...     print(lis.get_text()) ... <first li text> 22855157 22852085 <third li text> 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -