G
G
gregtar2017-09-07 10:50:11
Python
gregtar, 2017-09-07 10:50:11

How to parse a div with BeautifulSoup without IDs?

Good day. I decided yesterday to parse one of the sites in order to collect a database of clients with whom I can work and came across a problem: I can’t parse the div in which the phone is located because there are no identifiers.
For parsing, I use python 3 and the BeautifulSoup library. There were no problems with parsing the remaining fields. And here it doesn’t work at all, I already tried it using the css selector through nth-child (3).
8445af38f840471c9730790b859c6438.png880c4a92d8474b2896cba099b088e710.png
Since I don’t have much experience in parsing yet, please guide me on the right path)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-09-07
@LazyTalent

title = bs_obj.select('a.name_des.i')[0]
phone = title.find_next_sibling('div')

some_list = bs_obj.find('li', {'class': 'result_'})
phone = some_list.find_all('div')[1]

A
Anton B, 2017-09-07
@nizzit

You can find elements without a class like this: or
soup.findAll("div", attrs={'class': None})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question