MySQL:将csv导入带引号的表中

时间:2019-01-18 20:19:25

标签: mysql load-data-infile

我有一个csv,其中的每一行都以引号引起来,也以引号结束。将csv加载到表中时,如何忽略行开头和结尾的引号?

LOAD DATA LOCAL INFILE '/path/data.csv' 
INTO TABLE test1 
FIELDS TERMINATED BY ';' 
LINES TERMINATED BY '\"\n'
IGNORE 1 ROWS;

我尝试过

OPTIONALLY ENCLOSED BY '"'

但这是指每个特定字段,而不是整个行。

1 个答案:

答案 0 :(得分:1)

如Shadow和Barmar所评论,答案位于the documentation中:

  

如果所有输入行都有您要忽略的公共前缀,则可以使用LINES STARTING BY'prefix_string'来跳过该前缀及其前面的任何内容。如果一行不包含前缀,则会跳过整行。 [...]字段终止符,行起始符和行终止符可以是多个字符。

因此,请使用:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


link = 'https://www.eurobet.it/it/scommesse/#!/calcio/eu-champions-league/'
driver = webdriver.Chrome()
driver.get(link)

# Find the "ChanceMix" button by xpath and store it as a webdriver object
element = driver.find_element_by_xpath("//a[contains(text(), 'ChanceMix')]")

# Click on the "ChanceMix" button to open the relevant page
element.click()

# Find the list of games
Games = ui.WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.box-sport")))

# Print the list of games
for x in range(0,len(Games)): print(Games[x].text)