How to find string like in BeautifulSoup

martin tetley

how can i scrape if i know only half of the title of sibling in bs4?

from urllib.request import urlopen
from bs4 import BeautifulSoup as BS
from urllib import request
import pandas as pd
import os
import re
html = request.urlopen(https://en.wikipedia.org/wiki/Charles_Ehresmann)
bs = BS(html.read(), 'html.parser')
    
data = pd.DataFrame({''known for':[],)}
    try:
        name = bs.find('h1').text
    except:
        name = ''
    try:
        known = bs.find('th',string = 'Known.*').next_element.text #?
    except:
        known = ''

Thanks for ideas

QHarr

You can use :contains and next_sibling

from bs4 import BeautifulSoup as bs
import requests

r = requests.get('https://en.wikipedia.org/wiki/Charles_Ehresmann')
soup = bs(r.text, 'lxml')
print(soup.select_one('th:contains("Known")').next_sibling.get_text('\n').split('\n'))

Not as a list:

print(soup.select_one('th:contains("Known")').next_sibling.get_text('\n'))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to find subtimespan in a timespan like a string in python

BeautifulSoup find specific string

How to find all divs who's class starts with a string in BeautifulSoup?

How to find the second occurrence of a string using beautifulsoup in python

BeautifulSoup: how to find all the about attributes from html string

How to find a string inside a XML like tag from a file in Python?

How to search/find special characters like &, < or > in the string with regex using Python

How to find number sequence with multiple points in it like 1.2.3.4 from String?

How to find specific string within a group of like-named elements

How can I find HTML like tags in a string using Javascript?

how to do like query in MySQL find second word in string

How to find a sequence like this?

How to find substring like "N_N" in std::string like "SomeSymbolsN_NSomeSymbols" using regular expression

BeautifulSoup how to find XML tag?

how to find parent li in BeautifulSoup

How to search etree using lxml like BeautifulSoup

Beautifulsoup - Find an item by string in HTML with regex

Find String (Keyword) in title and description using Beautifulsoup?

BeautifulSoup find tag by string without children text

Find out the value of a string using BeautifulSoup

How to extract a specific string with BeautifulSoup

How to decode this string that Beautifulsoup process it?

python find_all_next in beautifulsoup can't find a string

How to find in postgres strings like %'%

Find a string in python beautifulsoup that shares the same class as other string

Find years in string like (90-)

Using LIKE to find something inside a string

Ruby find like string array from an array

How do i use grep command to find a text that includes a string like /usr/vm/data/?