Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created September 3, 2016 03:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/f844a1ff851c1df8a921e97a4d1f692e to your computer and use it in GitHub Desktop.
Save enginebai/f844a1ff851c1df8a921e97a4d1f692e to your computer and use it in GitHub Desktop.
def parse_shop_information(shop_link):
shop_id = re.sub(re.compile(r'^.*/' + SHOP_PATH), '', shop_link).split('-')[0]
print(shop_id)
req = requests.get(shop_link)
if req.status_code == requests.codes.ok:
soup = BeautifulSoup(req.content, HTML_PARSER)
shop_header_tag = soup.find('div', id='shop-header')
name_tag = shop_header_tag.find('span', attrs={'itemprop': 'name'})
print(re.sub(SPACE_RE, '', name_tag.text))
category_tag = shop_header_tag.find("p", class_={'cate i'})
print(re.sub(SPACE_RE, '', category_tag.a.text))
address_tag = shop_header_tag.find('a', attrs={'data-label': '上方地址'})
print(re.sub(SPACE_RE, '', address_tag.text))
gps_str = address_tag['href']
print(gps_str)
gps_str = re.search('/c=(\d+.\d*),(\d+.\d*)/', gps_str).group().replace('/', '')
print(gps_str)
lat = gps_str.split(',')[0]
lng = gps_str.split(',')[1]
print(lat.split('=')[1], lng)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment