Python Forum
BeautifulSoup : how to have a html5 attribut searched for in a regular expression ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BeautifulSoup : how to have a html5 attribut searched for in a regular expression ?
#1
Hi

The children of a node of the xml file I'm using all contain two ancient greek words as attributes, named «data-alpha» and «data-omega». Given an other greek word, I want to find out the node of which «data-omega» is alphabetically before this other word and of which next sibling's «data-alpha» is alphabetically after this word.

I've made it to search nodes based on attributes with regular expression, such as
def ltg1(classe):
	return classe is not None and classe=='js-char-popup-item symbols-grid__item u0000 '

def ltg2(classe):
	return classe is not None and re.compile('js-char-popup-item symbols-grid__item').search(classe) and not re.compile('^.*disabled$').search(classe)


def les_lettres(doc_html, choix):
	if choix=="ltg1":
		lst=doc_html.find_all(class_=ltg1)
	elif choix=='ltg2':
		lst=doc_html.find_all(class_=ltg2)
	for lt in lst:
		dt=eval('dict('+lt.attrs['data-template']+')')
		lettre, symbol, unicode = dt['title'],dt[ 'symbol'],dt[ 'number']
		print(lettre, symbol, unicode)
How can I do that ?

Arbiel
using Ubuntu 18.04.4 LTS, Python 3.8
having substituted «https://www.lilo.org/fr/» to google, «https://protonmail.com/» to any other unsafe mail service and bépo to azerty (french keyboard layouts)
Reply


Messages In This Thread
BeautifulSoup : how to have a html5 attribut searched for in a regular expression ? - by arbiel - May-05-2020, 10:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression rakhmadiev 6 5,369 Aug-21-2023, 01:52 PM
Last Post: Gribouillis
  Extract text from tag content using regular expression Pavel_47 8 5,219 Nov-25-2019, 03:17 PM
Last Post: buran
  Python x Html5 JohnnyCoffee 4 86,301 Oct-02-2019, 11:47 PM
Last Post: JohnnyCoffee
  web scraping with python regular expression dbpython2017 6 9,217 Sep-26-2017, 02:16 AM
Last Post: dbpython2017

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020