ファイルを読み込んで一行取得, 別のファイルに追記



# ファイルを読み込んで一行取得
with open('./csv/url.txt') as f:
    for url in f:

        driver.get(url)

        element = driver.find_element(By.ID, "productTitle")
        productTitle = element.text

        element = driver.find_element(By.CSS_SELECTOR, ".a-price-whole") #複数ある
        price = element.text
        price = price.replace(",", "")  #カンマ除去

        with open('csv/tmp.csv', 'a') as f:
            writer = csv.writer(f)
            writer.writerow([productTitle, price])
            print(productTitle)



Categories:

Tags: