Correctly save list to CSV file
Question:
Using the Selenium
library, I get some information (a table from the site) and try to save this table to a CSV file
.
elements_xpach_url = browser.find_element(By.XPATH, '/html/body/div[2]/span[2]/table/tbody[2]')
values = re.split('n', elements_xpach_url.text)
df = pd.DataFrame(values)
df.to_csv('csv.csv', index=False, header=False, sep=';')
In the final file, there is no way to set the division as a semicolon
;
instead of a space
.
print(type(values))
print(values)
Could you tell me please, how can this be implemented? Thank you very much!
Answers:
Given your data, you likely want to split your strings on spaces:
values = [re.split() for x in re.split('n', elements_xpach_url.text)]
df = pd.DataFrame(values)
Note that you do not need re.split
to split on newlines, str.split
is enough:
values = [re.split() for x in elements_xpach_url.text.split('n')]
df = pd.DataFrame(values)
Using the Selenium
library, I get some information (a table from the site) and try to save this table to a CSV file
.
elements_xpach_url = browser.find_element(By.XPATH, '/html/body/div[2]/span[2]/table/tbody[2]')
values = re.split('n', elements_xpach_url.text)
df = pd.DataFrame(values)
df.to_csv('csv.csv', index=False, header=False, sep=';')
In the final file, there is no way to set the division as a semicolon
;
instead of a space
.
print(type(values))
print(values)
Could you tell me please, how can this be implemented? Thank you very much!
Given your data, you likely want to split your strings on spaces:
values = [re.split() for x in re.split('n', elements_xpach_url.text)]
df = pd.DataFrame(values)
Note that you do not need re.split
to split on newlines, str.split
is enough:
values = [re.split() for x in elements_xpach_url.text.split('n')]
df = pd.DataFrame(values)