简体   繁体   English

如何水平保存Excel文件?

[英]How to save excel file horizontally?

Hi I am a code newbie and I want to save data that I got through a website (editor.cnn.com) as an excel file but I don't get the result the way I want. 嗨,我是一个代码新手,我想将通过网站(editor.cnn.com)获得的数据保存为excel文件,但我无法获得想要的结果。

Because I want to save all the 'lines' or 'data' horizontally in an excel file. 因为我想将所有“行”或“数据”水平保存在excel文件中。

So here is my code. 这是我的代码。 Can you tell me what I have to change or add in my code? 您能告诉我我必须更改或添加的代码吗?

Thank you in advance! 先感谢您!

before 之前

after.. problem solved!! 之后..问题解决了!!

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import requests
import time
import pandas as pd
import os
from bs4 import BeautifulSoup as soup
from bs4 import NavigableString
import re

path = "/Users/Downloads/chromedriver.exe"
driver = webdriver.Chrome(path)


nl = []

driver.get("https://edition.cnn.com/")
driver.implicitly_wait(3)
html = driver.page_source
soup = BeautifulSoup(html, "lxml")
find_ingre = soup.select("div.cd__content")
for i in find_ingre:
    nl.append(i.get_text())

import pandas as pd
from pandas import Series, DataFrame

df_4 = pd.DataFrame(nl)
df_4

Instead of pandas, you can use openpxl to create excel file: 您可以使用openpxl而不是熊猫来创建excel文件:

from openpyxl import Workbook

wb = Workbook()
ws = wb.active

# Append all results as row
ws.append(nl)
wb.save("yourfile.xlsx")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM