python - 从 read_html 源写入 csv 文件
问题描述
我无法将 html 表(表 2)导出到 csv 文件。我尝试在对象 pd.read_html 上使用 to_csv 但不工作
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import html.parser
import pandas as pd
import time
driver=webdriver.Chrome("C:/Users/Juan Diego Bernate V/Documents/Python/Practica/APIs/chromedriver.exe")
driver.get('https://www.ambito.com/contenidos/dolar-futuro.html')
res=driver.execute_script("return document.documentElement.outerHTML")
html=driver.page_source
soup= BeautifulSoup(html, 'lxml')
tabla=soup.find_all('table')
tabla2=pd.read_html(html)
dia = time.strftime("%Y%m%d")
ruta='C:/Users/Juan Diego Bernate V/'
nombre= ruta+ 'dolar_fut_rofex_2'+dia+'.csv'
tabla2.to_csv(nombre)
print (tabla2)
print (tabla)
这是错误信息,我写了我使用的所有代码,之前,我认为它不相关。
DevTools 监听 ws://127.0.0.1:54234/devtools/browser/6a47dd26-ab5d-4318-b858-226180882e0f Traceback(最近一次调用最后):文件“WSDinamicoRofex.py”,第 34 行,在 tabla2.to_csv(nombre ) AttributeError: 'list' object has no attribute 'to_csv' 希望你能帮助我
解决方案
推荐阅读
- android - 从 android 移动设备连接到 localhost rest api
- r - 使用 R 读取带有文本的 xls 文件
- java - 当我执行意图时,Textview的内容被删除(Android Studio)
- laravel - 如何构建使用 Cloudflare Workers KV 作为数据存储的 Laravel 缓存驱动程序?
- awk - awk 从键值对打印一个值
- rcpp - R包AsioHeaders的链接问题
- javascript - Axosoft/nsfw 文件监视器不会触发文件更改
- java - VsCode 从编译过程中删除文件夹
- r - 加入两个数据框并消除重复项
- bash - 计算多个文件中单词列表的出现次数