Reputation: 57
Currently I am using Selenium to scrape a website and it is working nicely up until now. I have Selenium find some text on a page and push it to an Array which will then be output to a CSV file. My problem is in how it is parsing the text it is grabbing.
The code in question is:
payload.extend(driver.find_element_by_id("psa_retailPriceDisplay").text)
The output to the array is:
['xxxx-1234', u'$', u'3', u'2', u'9', u'.', u'9', u'5']
And I need it in the format:
['xxxx-1234','$329.95']
The first value is already in the array. I have tried encoding it in utf-8 along with a few other things but am not sure how to move forward.
Payload is my current array. I am planning on appending all data to payload.
Upvotes: 0
Views: 438
Reputation: 20563
Try this:
new_list = [str(output[0]), str(''.join(output[1:]))]
with output[0]
keeping the first element in the list, and combine the rest with join()
, and convert to string using str()
.
Upvotes: 1