Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Removing spaces from list items after parsing

Павел Захаров:

I can not Remove spaces from list items after Parsing. Here is the fully working code.


​from bs4 import BeautifulSoup
from selenium import webdriver
import pandas as pd
import xlwings as xw
driver = webdriver.PhantomJS()
driver.get("http://ift.tt/2AuXo8j")
driver.find_element_by_id('UniDbQuery_FromDate').clear()
driver.find_element_by_id('UniDbQuery_FromDate').send_keys('11.12.2017')
driver.find_element_by_id('UniDbQuery_ToDate').clear()
driver.find_element_by_id('UniDbQuery_ToDate').send_keys('13.12.2017')
driver.find_element_by_id("UniDbQuery_searchbutton").click()
z=driver.page_source
driver.quit()
soup=BeautifulSoup(z)
x=[]
for tag in soup.tbody.findAll('td'):
x.append(tag.text)
y=x[1::2]
y
['381 970,85', '370 534,87', '374 626,19']

The following code does not remove spaces.


​for i in y:
i=i.replace(' ', '')
​y
['381 970,85', '370 534,87', '374 626,19']

Another code also does not clear the spaces.


​y = [x.strip(' ') for x in y]
​y
['381 970,85', '370 534,87', '374 626,19']

Please help to solve this problem. But please do not give advice if you have not tried your code.

I think the problem is in the encoding. But this assumption, since I'm new to programming.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Removing spaces from list items after parsing

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×