D
D
Dmitry2016-11-30 18:01:38
Python
Dmitry, 2016-11-30 18:01:38

Is it possible in BeautifulSoup4 to have "random" access in a tag array after a search using a CSS selector?

When parsing html (websites) in Python-e using the library specified in the subject, I really "stumble" on inconvenient work with tags after

DOWNLOAD_URL = 'http://super-mega-program.org/download.html'
html_page = urlopen(self.DOWNLOAD_URL)
soup = BeautifulSoup(html_page, 'html.parser')
css_selector = 'ТУТ ОЧЕНЬ СЛОЖНЫЙ СТРИНГ'
versions_box = soup.select(css_selector)[0]
p_tags = versions_box.findAll('p', {'class': 'editions'})
ver1 = p_tags[0].i.getText().split()[1]
ver2 = p_tags[5].i.getText().split()[1]

What I don't like here is that I'm forced to call findAll() . I would like something like this:
versions_box.p[0].i.text.split()[1]
versions_box.p[5].i.text.split()[1]

Maybe I don’t know something and there are more convenient ways to work, something like in this example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nwton, 2017-03-24
@tolyan2115

15b6aa00c1a8440fba80e7ee0208072b.PNG
whaff.com/content/whaff/img/main_bg_addiphone.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question