Split a long string into other strings with no delimiters/characters - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Split a long string into other strings with no delimiters/characters (/thread-22501.html) |
Split a long string into other strings with no delimiters/characters - krewlaz - Nov-15-2019 So I am web scraping an eBay sales history web-page using BeautifulSoup. Here's the webpage: An example of the results I get are: Depending on the item ID I put in, it will be slightly different. For example, another result: I would like to split these strings so it's like this: or for the second example: I have no idea where to start here, but I would imagine splitting the price part 2 characters after the "." maybe? Any help here would be greatly appreciated as I am lost!
RE: Split a long string into other strings with no delimiters/characters - ichabod801 - Nov-15-2019 Well, you want everything up to an including the first ')', then everything from there to the first pound sign. The the first pound sign to two digits after the decimal, then one character, then split the rest at the space. You can find where those characters are with the index method of the string, and then just use slicing to split it apart. RE: Split a long string into other strings with no delimiters/characters - baquerik - Nov-15-2019 Was that whole string between the same tags in the original web? RE: Split a long string into other strings with no delimiters/characters - krewlaz - Nov-15-2019 (Nov-15-2019, 02:17 PM)baquerik Wrote: Was that whole string between the same tags in the original web? It's all one string between the same tags, yes. I think I might be able to figure this out - but my question is, can I split a string 2 characters after another character? For example, can I split a string 2 characters after a . ? RE: Split a long string into other strings with no delimiters/characters - ichabod801 - Nov-15-2019 dot = text.index('.') two_after = text[:dot + 2] tail = text[dot + 2:] |