commented!
This commit is contained in:
parent
a9d0d006ab
commit
1c9216ac1d
1 changed files with 13 additions and 2 deletions
|
@ -19,26 +19,37 @@ def get_steam_info(url):
|
||||||
# get the element details_block
|
# get the element details_block
|
||||||
details = soup.find('div', {'class': 'details_block'})
|
details = soup.find('div', {'class': 'details_block'})
|
||||||
|
|
||||||
# MAGIC
|
# loop over every <b></b> tag in details_block
|
||||||
for b in details.findAll('b'):
|
for b in details.findAll('b'):
|
||||||
|
# get the contents of the <b></b> tag, which is our title
|
||||||
title = b.text.lower().replace(":", "")
|
title = b.text.lower().replace(":", "")
|
||||||
if title == "languages":
|
if title == "languages":
|
||||||
# we have all we need!
|
# we have all we need!
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# find the next element directly after the <b></b> tag
|
||||||
next = b.nextSibling
|
next = b.nextSibling
|
||||||
if next:
|
if next:
|
||||||
|
# if the element is some text
|
||||||
if isinstance(next, NavigableString):
|
if isinstance(next, NavigableString):
|
||||||
text = next.string.strip()
|
text = next.string.strip()
|
||||||
if text:
|
if text:
|
||||||
|
# we found valid text, save it and continue the loop
|
||||||
data[title] = text
|
data[title] = text
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
# the text is blank - sometimes this means there are
|
||||||
|
# useless spaces or tabs between the <b> and <a> tags.
|
||||||
|
# so we find the next <a> tag and carry on to the next
|
||||||
|
# bit of code below
|
||||||
next = next.find_next('a', href=True)
|
next = next.find_next('a', href=True)
|
||||||
|
|
||||||
|
# if the element is an <a></a> tag
|
||||||
if isinstance(next, Tag) and next.name == 'a':
|
if isinstance(next, Tag) and next.name == 'a':
|
||||||
text = next.string.strip()
|
text = next.string.strip()
|
||||||
if text:
|
if text:
|
||||||
|
# we found valid text (in the <a></a> tag),
|
||||||
|
# save it and continue the loop
|
||||||
data[title] = text
|
data[title] = text
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Reference in a new issue