Python Forum
Split a long string into other strings with no delimiters/characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split a long string into other strings with no delimiters/characters
#1
So I am web scraping an eBay sales history web-page using BeautifulSoup. Here's the webpage:
[Image: 1W1GRfj.png]

An example of the results I get are:

Output:
9***o( 62) Size: 30W: 30cm x 50cm (12" x 20")£22.99112-Aug-19 14:03:10 BST f***e( 1419) Size: 10W: 15cm x 25cm (6" x 10")£15.99111-Aug-19 10:03:05 BST
Depending on the item ID I put in, it will be slightly different. For example, another result:

Output:
8***t( 291) Fluval External Filter: Fluval 307 External Filter£129.99127-Jul-19 14:02:54 BST _***2( 1401) Fluval External Filter: Fluval 407 External Filter£177.99126-Jul-19 23:54:21 BST
I would like to split these strings so it's like this:

Output:
"9***o( 62)", "Size: 30W: 30cm x 50cm (12" x 20")", "£22.99", "1", "12-Aug-19", "14:03:10 BST"
or for the second example:
Output:
"_***2( 1401)", "Fluval External Filter: Fluval 407 External Filter", "£177.99", "1", "26-Jul-19", "23:54:21 BST"
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!
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Was that whole string between the same tags in the original web?
Reply
#4
(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 . ?
Reply
#5
dot = text.index('.')
two_after = text[:dot + 2]
tail = text[dot + 2:]
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 207 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Split string between two different delimiters, with exceptions DreamingInsanity 2 276 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Introduction to escaping characters in strings Geelong_crazy 1 297 Jul-18-2020, 06:58 PM
Last Post: DT2000
  How to find the first and last of one of several characters in a list of strings? tadsss 2 381 Jun-02-2020, 05:23 PM
Last Post: bowlofred
  split string enigma619 1 275 May-20-2020, 02:47 PM
Last Post: perfringo
  How to get first two characters in a string scratchmyhead 2 372 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  question: finding multiple strings within string djf123 4 542 May-16-2020, 01:00 PM
Last Post: snippsat
  Remove escape characters / Unicode characters from string DreamingInsanity 5 957 May-15-2020, 01:37 PM
Last Post: snippsat
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 534 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  Problem with delimiters johnprada 5 606 Jan-29-2020, 10:17 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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