【发布时间】:2022-01-11 05:01:04
【问题描述】:
我正在尝试使用 Selenium 将以下 DataFrame 发送到资本收益计算器网站 (http://www.cgtcalculator.com/calculator.aspx) 的文本字段中。
B 01/12/2000 BARC 3000 4.82 15 72.3
B 02/12/2000 BARC 5000 4.825 15 120.62
B 03/09/2002 VOD 18000 3.040 10 273.60
B 15/01/2003 BP. 5000 3.750 10 93.75
B 24/03/2003 BP. 3000 3.820 10 57.30
S 14/04/2003 BARC 6000 5.520 15 0.00
S 23/02/2004 VOD 9000 3.620 10 0.00
S 24/02/2004 VOD 9000 3.625 10 0.00
S 15/07/2005 BP. 8000 6.280 10 0.00
B 22/01/2007 BP. 5000 5.500 10 124.20
B 22/06/2009 BP. 2000 5.020 10 50.20
S 24/12/2012 BP. 5000 4.336 10 0.00
到目前为止,我能够单独发送每一列,但问题是这些列在文本字段中出现在另一列之下。为了让计算器工作,我需要保持 DataFrame 的格式。有没有办法做到这一点?
这是我到目前为止所做的:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pandas as pd
df = pd.read_csv("/Users/Test.csv")
driver = webdriver.Chrome()
driver.get("http://www.cgtcalculator.com/calculator.aspx")
inputElement = driver.find_element_by_id("TEXTAREA1")
inputElement.send_keys("\n".join(df. iloc[:, 0]),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 1]),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 2]),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 3].astype(str)),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 4].astype(str)),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 5].astype(str)),"\n")
inputElement.send_keys("\n".join(df. iloc[:, 6].astype(str)),"\n")
driver.find_element_by_id("Button3").click()
driver.find_element_by_id("Button1").click()
【问题讨论】: