0

Here is what I get for the Code

Input: contents = bs.find_all('div', {'class':'result_list'})

Output:

<div class="result_list" id="search-list"><div class="sight_item" data-address="广州市番禺区大石镇105国道大石段593号" 
data-children-count="17" data-districts="广东·广州·广州长隆旅游度假区" data-foreign="false" data-id="4281924223"
data-point="113.321711,23.007944" 

So I want to extract the information inside the ResultSet.

For examples,

I want to get the 'data-address' and 'data-point'.

So what should I do?

  • [This](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) might help – Aven Desta Apr 13 '21 at 07:03

1 Answers1

0

First there should be a closing div tag for the html code. So lets make the output of contents this

<div class="result_list" id="search-list">
  <div class="sight_item" data-address="广州市番禺区大石镇105国道大石段593号" 
    data-children-count="17" data-districts="广东·广州·广州长隆旅游度假区" 
    data-foreign="false" data-id="4281924223"
    data-point="113.321711,23.007944">

      DIV CONTENT GOES HERE!

  </div>
</div>

Also contents should be a list of div tags, so lets access the first element of the list with [0]

So try this one.

contents = bs.find_all('div', {'class':'result_list'})
# contents is now a list of divs
sight_item = contents[0].div.div
data_address = sight_item['data-address']
print(data_address)


# output
# 广州市番禺区大石镇105国道大石段593号

data_point = sight_item['data-point']
print(data_point)

#output
# 113.321711,23.007944
Aven Desta
  • 2,114
  • 12
  • 27