I'm using Python and I have an HTML-code which I want to chop off as soon as it reaches the word "toc", but I can't figure out how to do, anyone having some nice ideas?
Chop off text when it reaches certain word in Python
147 Views Asked by Samuel Håkansson At
2
There are 2 best solutions below
0
Mazdak
On
You can just use split :
>>> s="""<html lang="en" dir="ltr" class="client-nojs"> <head> <meta charset="UTF-8" /> <title>IBM - Wikipedia, the free encyclopedia</title> <meta name="generator" content="MediaWiki 1.25wmf19" />"""
>>> s.split('UTF')[0]
'<html lang="en" dir="ltr" class="client-nojs"> <head> <meta charset="'
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in SLICE
- String slice in a const function
- 2024 golang a slice of length 2 append 3 more elements, why does it have length 5 capacity 6 instead of capacity 5?
- How to do Python-style array slicing in Java?
- The performance impact of removing elements from the front of the slice
- python replace in string
- Why iterating over slice may be slower than over map in Go?
- How to return a slice in Java
- Adding numpy arrays to cells of a pandas DataFrame depends on initialisation
- How do I determine a slice to make sure it only accepts float32 or uint32?
- slicing pandas columns individually between first and last valid index
- Why slicing of [:0] does not return an error?
- Go, 2-dimensional array (or slice) of struct
- Pandas slicing by index inconsistency
- Index_slicing_problem
- pandas slice 3-level multiindex based on a list with 2 levels
Related Questions in TABLEOFCONTENTS
- Table of Contents (TOC) in a RTF document. Formatting problem with PAGEREF
- MediaWiki Table of Contents - Use CSS to: Scroll not working or being overridden
- DOCX4J not updating TOC
- C# Itext7 Table of Content link to chapter does't work
- R Markdown in R - TOC get stuck when using {.tabset} in headings (#)
- Prevent title page, preface etc from being listed in table of contents. Bookdown pdf output
- Problem creating table of content page in HTML without ID
- Extract table of content of a book with ocr
- render_site() function destroys hypertext links
- Using table of contents and chapterbib
- How to add a symbol such as > besides ... the end of a heading if that it has sub-headings in org-mode when collpased?
- How to adjust the right hand toc depth in Jupyter Notebook
- Choose font size for table of contents only in a rmarkdown-rendered pdf
- Extract table of content from docx python
- Spacings in TOC in a beamer presentation
Related Questions in CHOP
- Remove horizontal slice of an image and fill its void by the surrounding areas from above and below
- Chop a file in Julia
- How can I chop a large and growing CSV file in python
- How to make an efficient algorithm for chopping a binary search tree into two by given value?
- Intellij IDEA setting for "method call argument:s chop down if long" misbehaving
- Using chop in grep expression
- How to use chop with if in Mathematica?
- Qt C++ How to chop a letter of QString that is member of a QStringList in 1 command
- Chop last character of string
- Chop() is chopping more than what is asked
- Query on Android detecting chop twice using accelerometer
- How can I refine PHP sub-string and chop functions
- Chop off text when it reaches certain word in Python
- Issue chopping series of strings Bash with asterisks
- perl remove trailing line not working
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Without more information, something like the following works
But be aware that this will catch words like "stock" -- so there's likely a better approach depending on your specifics.