是否将Int读取为文本?蟒蛇

时间:2018-07-11 23:29:04

标签: python csv

我抓取了一个网站,并将信息保存到CSV文件中。但是,抓取的部分信息是数字,在excel中打开时,这些单元格首先看起来是空的,然后要求我双击每个单元格才显示数据。一旦数据可见,它就不会被读为数字,而是被读为文本(或者甚至不被读为文本),因为我也尝试在excel上实现文本到int的转换,以及当我尝试转换时文本只是删除了单元格中的所有信息。 任何帮助表示赞赏。

import math
import sys
from bs4 import BeautifulSoup
import csv
import requests
import re 
source = requests.get('https://www.example.com').text
soup = BeautifulSoup(source, 'lxml')

csvfile = open('example.csv', 'wt', newline='')
try:
    writer = csv.writer(csvfile)
    writer.writerow('')
    for teams in soup.find_all('span', class_="name ib"):
        writer.writerow(team)
finally:
     csvfile.close()

## Also if instead of saving the 2nd portion of the program starting from the 
## second csv open, and I  
## instead change the code to directly display the information in the 
## console, the entire html tag is displayed, not just the information inside 
## of the tag 



csvfile = open('example2.csv', 'wt', newline='')
try:
    writer = csv.writer(csvfile)
    writer.writerow('')
    for odds in soup.find_all('span', class_=re.compile(r"price-val_.")):
       writer.writerow(value)


finally:
    csvfile.close()

Excel屏幕截图

[excel screenshot](https://imgur.com/a/L0KHGvW)

0 个答案:

没有答案