Jul-05-2019, 07:10 AM
(This post was last modified: Jul-05-2019, 07:10 AM by starter_student.)
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!
File "haagen_store.py", line 4, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
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'