If you open a CSV file created with VScode with numbers, it becomes blank.

Asked 1 years ago, Updated 1 years ago, 58 views

Prerequisites/What you want to achieve

If you open a CSV file created with VScode with numbers, it will be blank, so I would like to resolve it.

I was able to create a CSV file made with VScode, but when I move the file to the desktop and open it with numbers, it becomes blank.

*Image created with PyCharm and opened with numbers after moving to the desktop⬇ br
Enter a description of the image here

*Image created with VScode and opened with numbers after moving to the desktop⬇ br
Enter a description of the image here

Source Codes Affected

 from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import pandas aspd
from print import print



chrome_path='/Users/nakamotookenta/Desktop/ScrapingBeginner-main/chromedriver'

options=Options()
options.add_argument('--incognito')

driver=webdriver.Chrome(executable_path=chrome_path, options=options)

url='https://search.yahoo.co.jp/image'
driver.get(url)

sleep(3)

query='cat'
search_box=driver.find_element_by_class_name('SearchBox__searchInput')
search_box.send_keys(query)
search_box.submit()

sleep(3)

height = 50
while height <150:
    driver.execute_script("window.scrollTo(0,{});".format(height))
    height+=100
    print(height)

    sleep(1)

# Select an element of the image
elements=driver.find_elements_by_class_name('sw-Thumbnail')

print(len(elements))

d_list = [ ]
# Obtain URL from element
for i, element in enumerate (elements, start=1):
    name=f'{query}_{i}'
    raw_url = element.find_element_by_class_name('sw-ThumbnailGrid__details').get_attribute('href')
    yahoo_image_url=element.find_element_by_tag_name('img') .get_attribute('src')
    title=element.find_element_by_tag_name('img') .get_attribute('alt')

    d = {
        'filename': name,
        'raw_url': raw_url,
        'yahoo_image_url': yahoo_image_url,
        'title': title
    }

    d_list.append(d)

    sleep(2)

    print('finished{}.format(name))

print(d_list)
df = pd.DataFrame(d_list)
print(df.head())
print(df.shape)
df.to_csv('image_url_20210823.csv')

driver.quit()

Tried

Run the same code as VScode in PyCharm, move it to the desktop, and open it in numbers to create a table instead of blank.

Supplementary information (for example, FW/Tool Version)

macOS Big Server 11.5
numbers version 11.1

editor
①PyCharm2021.2 (Community Edition)
python 3.9

VSVscode version: 1.59.1
python 3.8.8 64-bit ('base':conda)

追Additional
I didn't know that multi-posting was not recommended, so I thought I could solve it quickly, so I posted a question on other services.
⬇ その is that site
[https://teratail.com/questions/355847]

追Additional note 2 (dump the first 256 bytes of each file)
● CSV file created with PyCharm⬇ br
「2C66696C 656E616D 652C7261 775F7572 6C2C7961 686F6F5F 696D6167 655F7572 6C2C7469 746C650A 302CE381 ADE38193 5F312C68 74747073 3A2F2F74 6F796F6B 65697A61 692E6E65 742F6172 7469636C 65732F2D 2F333337 3435342C 68747470 733A2F2F 6D73702E 632E7969 6D672E6A 702F696D 61676573 2F76322F 46555469 39337458 71343035 67725A56 47674471 477A6762 7273786D 705A6D56 5A544345 64723931 6276464A 666C5757 3359657A4A36535359617971 306E5048 66773337 76425777 776E2D32616C67464A354C6B344C3147 49776354 426A5A79544496B 37552D587466754D58684534456C31516A4A565625477A325F3F314A73"

● CSV file created with VScode⬇ br

I didn't see anything here.

*Additional 3
I found the file I created in VScode in Finder and double-click on Finder to see the table I created in numbers! (The table I created in PyCharm is the same as the one I used to drag and drop on my desktop!)
The CSV file is blank only when you drag & drop it in VSccode.

python vscode csv pycharm

2022-09-30 16:56

1 Answers

Cubick, Kunif, oriri, thank you for your reply!
We have achieved the goal of displaying CSV files created with VScode with numbers (and on the desktop)!

df.to_csv('/Users/nakamotookenta/Desktop/potesara.csv')

I was able to save it to my desktop by rewriting it to
Thank you very much!
I will also post a solution to what I have posted on other sites!

* I took the one that I saved on my desktop to VScode and brought it back to my desktop, and it went blank again, but now that I have achieved my goal, I will accept it.


2022-09-30 16:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.