从所有H-Mart位置创建地址簿

I am trying to scrape the H-Mart webpage to pull all the addresses and create a spreadsheet out of it.

到目前为止,我的代码如下:

from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
import requests
import html5lib
import os
import io
import sys

url = 'https://www.hmart.com/ourstores'
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,'cp437','backslashreplace')
page = requests.get(url).text
soup = BeautifulSoup(page, features = 'html.parser')
#soup = BeautifulSoup(page, features = 'html.parser').encode('utf-8')
text = soup.get_text()
soup = soup.prettify()

stores = soup.find('div', {'class':'stores-list'})

print(stores)

但是,我的最新代码已生成以下错误消息:

Traceback (most recent call last):
  File "c:\mypath\myscript.py", line 18, in <module>
    stores = soup.find('div', {'class':'stores-list'})
TypeError: slice indices must be integers or None or have an __index__ method

以下是我要抓取的网页中一些html的示例(但您也可以单击超链接以查看完整的html)。

       <div class="stores-list">
        <div class="store-item">
         <strong>
          California
         </strong>
         <ul class="clearer">
          <li>
           <a class="store-name" href="https://www.hmart.com/storelocator/index/index/id/59/" title="Arcadia">
            Arcadia
           </a>
           <span class="restaurant">
            <img alt="restaurant" src="https://www.hmart.com/static/version1588680879/frontend/Eguana/hmart/en_US/Kensium_Storelocator/images/location/ico-food-court.png"/>
           </span>
          </li>

我确实在完整的html中注意到了一些json内容,这些内容可能(?)可以很容易地为我提供正在寻找的数据,但是我不知道如何将其充分发挥。任何使该代码正常工作以及使该电子表格创建的建议将不胜感激。

评论