473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

BeautifulSoup extract certain information after located text?

From html page:

Expand|Select|Wrap|Line Numbers
  1. <div class="peoples-info">
  2. <ul>
  3. <li><strong>Gender:</strong> F</li>
  4. <li><strong>Birthdate:</strong> 00/00/2000</li>
  5. <li><strong>Family Phone:</strong> 000-000-0000</li>
  6. <li><strong>Personal Phone:</strong> 000-000-0000</li>
  7. </ul>
  8. </div>
  9. </div>
  10. <div>
I wanted to extract using BeautifulSoup's find_next function, but I could only do tables such as:

Expand|Select|Wrap|Line Numbers
  1. for gender in soup.find('td', text='gender:'):
  2.     print(gender.find_next("td").text)
Which does not work with div when I replace "td" with "li"; also, title and number are in the same line with only the format changed a bit. Is there a way to extract only information such as phone numbers and birthdays without their titles ("000-000-0000")? Thanks!
Aug 8 '21 #1
1 2844
SioSio
272 256MB
This is a brute force way,
Expand|Select|Wrap|Line Numbers
  1. peoplesinfo = soup.find('div', class_='peoples-info')
  2. for element in peoplesinfo.find_all("li"):
  3.     el = element.find_all("strong")
  4.     print(element.text.replace(el[0].text, ''))
Aug 16 '21 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Vjay77 | last post by:
I posted this question, but I pressed 'post' and it disappeared. So once again: Problem: I need to go to lets say www.site.com/page.html Imagine that this html code is 6 mb long. I need to...
7
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a...
8
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
1
by: gcmartijn | last post by:
I'm trying to extract something like this: <object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/...
1
by: Computernut234 | last post by:
Hi, i'm doing a project for my Java class and I know how to add text to a .txt document and remove the entire text but I do not know how to only remove certain parts of text. My code is supposed to...
0
by: wbw | last post by:
I am trying to extract capitalized words from text in Excel. I have a list of a combination of brands and products and I am trying to extract out the product attribute from the text. Since the text...
12
by: maximus tee | last post by:
i want to extract certain section of the text file. my input file: -- num cell port function safe "17 (BC_1, CLK, input, X)," & "16 (BC_1, OC_NEG, input, X), " &-- Merged input/ " 8...
8
by: ryaanmichael | last post by:
VBA question for Access 2010: I have a MEMO field in a form where users will paste a few lines of information. The structure/characters of the pasted information will always be in the same format,...
5
by: jdb1229 | last post by:
I am completely new to Access. I received some great help with another question I had so I was hoping to get some assistance with another. I have never coded before I started this project so I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.