Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beautiful soup and tags
#1
Hi everyone,

I'm trying to do a loop inside a div tag with others div tags but how to find all the children of that div!

<div id ="storelist" class>
   <ul> 
        <li id ="00021455" class>
         .
         .
         .
              <div class ="wr-store-details">
                  <h3> class "Store abc"</h3>
                  <span> class ="20005 dc">
                  <span> class ="LA">
    </ul>
</div>

#code
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import csv 
import requests 
  
URL = "http:www.abc.com"
r = requests.get(URL) 
  
soup = BeautifulSoup(r.content, 'html5lib') 
  
store_details_tab = []  # a list to store store_details-tab 
  
table = soup.find('div', attrs = {'id':'storelist'}) 
  
for row in table.findAll('div', attrs = {'class':'store_details'}): 
    store_details = {} 
    store_details['store_name'] = row.div.text 
    store_details['store_address'] = row.span.text 
    store_details['store_city'] = row.span.text 
    store_details_tab.append(store_details) 
  
filename = 'store_details_tab.csv'
with open(filename, 'wb') as f: 
    w = csv.DictWriter(f,['store_name','store_address','store_city']) 
    w.writeheader() 
    for store_details in store_details_tab: 
        w.writerow(store_details)
error: Traceback (most recent call last):
File "haagen_store.py", line 4, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Reply


Messages In This Thread
Beautiful soup and tags - by starter_student - Jul-05-2019, 07:10 AM
RE: Beautiful soup and tags - by perfringo - Jul-05-2019, 07:18 AM
RE: Beautiful soup and tags - by starter_student - Jul-05-2019, 08:46 AM
RE: Beautiful soup and tags - by perfringo - Jul-05-2019, 09:19 AM
RE: Beautiful soup and tags - by starter_student - Jul-08-2019, 06:18 AM
RE: Beautiful soup and tags - by perfringo - Jul-08-2019, 06:39 AM
RE: Beautiful soup and tags - by starter_student - Jul-08-2019, 07:32 AM
RE: Beautiful soup and tags - by Larz60+ - Jul-05-2019, 11:21 PM
RE: Beautiful soup and tags - by snippsat - Jul-08-2019, 10:15 AM
RE: Beautiful soup and tags - by starter_student - Jul-08-2019, 12:16 PM
RE: Beautiful soup and tags - by snippsat - Jul-08-2019, 02:15 PM
RE: Beautiful soup and tags - by starter_student - Jul-08-2019, 03:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Soup('A') new_coder_231013 6 2,628 Aug-12-2023, 10:55 AM
Last Post: Pubfonts
  Beautiful Soup - access a rating value in a class KatMac 1 3,506 Apr-16-2021, 01:27 PM
Last Post: snippsat
  *Beginner* web scraping/Beautiful Soup help 7ken8 2 2,667 Jan-28-2021, 04:26 PM
Last Post: 7ken8
  Help: Beautiful Soup - Parsing HTML table ironfelix717 2 2,744 Oct-01-2020, 02:19 PM
Last Post: snippsat
  Beautiful Soup (suddenly) doesn't get full webpage html j.crater 8 17,220 Jul-11-2020, 04:31 PM
Last Post: j.crater
  Requests-HTML vs Beautiful Soup - How to Choose? robin73 0 3,857 Jun-23-2020, 02:53 PM
Last Post: robin73
  looking for direction - scrappy, crawler, beautiful soup Sly_Corn 2 2,494 Mar-17-2020, 03:17 PM
Last Post: Sly_Corn
  Beautiful soup truncates results jonesjoz 4 3,973 Mar-09-2020, 06:04 PM
Last Post: jonesjoz
  Beautiful Soup find_all() kirito85 2 3,417 Jun-14-2019, 02:17 AM
Last Post: kirito85
  [split] Using beautiful soup to get html attribute value moski 6 6,367 Jun-03-2019, 04:24 PM
Last Post: moski

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020