Python Forum
Finding First Digits in String
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding First Digits in String
#1
Hello Everyone, I am currently having a problem with capturing numbers at the end of the h3 tags highlighted in red and the bold and italics are the numbers I am trying to capture. The following script I have updated to facilitate the update of the paragraphs: one I notice the numbers were at the end of other h3 tags as well. Unfortunately, I have having a difficult time completing this task of using two list to find the first number after the h3 tag. How can I use regex to find the first digits after the h3 tags using the if statement to capture 1 after He poured rocks and the 6 after When Cooking . This is the current script it only pulls the first number and not the 6 after the next h3 tag. What modifications do I need to make to solve this issue? Thank you for your assistance in this matter.

for dc in soup.findAll('div', {'class':'flex flex-auto flex-col bg-white shadow-md'}):
        
        txt = re.sub('\[(.*?)\]','',dc.text) #Take out text on and between []             
        ##print('div class text',txt) #Print div class text


        for h3 in soup.findAll('h3', {'class':'font-medium block subject-heading text-xl mb-3 mt-5'}):
             hcls = h3.text #H3 Class text
             
             print('This is h3 class text ',h3.text)

             if hcls in txt:
                 
                 fn = re.findall(r'^hcls|[\d+|$]',txt)[0] #find First Numbers
                 
                 print('This is first number after the h3 tag',fn)
Quote:data
He poured rocks 1 in the dungeon of his mind.

Joyce enjoyed eating pancakes with ketchup.

2

I think I will buy the red car, or I will lease the blue one.



3

He had decided to accept his fate of accepting his fate.



The tumbleweed refused to tumble at 8 but was more than willing to prance.



The two walked down the slot canyon for 2 miles oblivious to the sound of thunder in the distance



4

He used to get confused between soldiers and shoulders, but as a military man, he now soldiers responsibility.

5

Harrold felt confident that nobody would ever suspect his 2 spy pigeons.



When Cooking 6 It smells very delicious in the kitchen.
Reply
#2
Useful reading Big Grin before you try use regex on HTML: https://stackoverflow.com/a/1732454/8663760
giddyhead likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Post link to site or the raw html,then it easier to suggest a soliton.
giddyhead likes this post
Reply
#4
(Aug-12-2022, 07:53 AM)snippsat Wrote: Post link to site or the raw html,then it easier to suggest a soliton.


Quote:Thanks I found a solution! Once again. Thanks
Reply
#5
(Aug-12-2022, 06:59 AM)perfringo Wrote: Useful reading Big Grin before you try use regex on HTML: https://stackoverflow.com/a/1732454/8663760


Quote:Thanks I found a solution! Once again. Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Finding string in list item jesse68 8 1,895 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Single digits seem to be greater than double digits Frosty_GM 4 3,521 Nov-20-2020, 10:13 AM
Last Post: DeaD_EyE
  Please support regex for version number (digits and dots) from a string Tecuma 4 3,207 Aug-17-2020, 09:59 AM
Last Post: Tecuma
  Add new line after finding last string in a region Nigel11 1 1,891 Aug-08-2020, 10:00 PM
Last Post: Larz60+
  Finding line numbers starting with certain string Sutsro 3 2,563 Jun-27-2020, 12:36 PM
Last Post: Yoriz
  question: finding multiple strings within string djf123 4 3,001 May-16-2020, 01:00 PM
Last Post: snippsat
  Searching for digits followed by a string. Zen_Panda 1 2,027 Feb-25-2019, 11:06 AM
Last Post: scidam
  Input a number with any number of digits and output it in reverse order of digits. sarada2099 6 6,683 Mar-12-2017, 05:45 PM
Last Post: Ofnuts
  Finding Special Characters in a String ATXpython 4 19,817 Sep-30-2016, 10:08 PM
Last Post: ATXpython

Forum Jump:

User Panel Messages

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