【问题标题】:How to convert xlsx file with html code inside to pandas library?如何将带有html代码的xlsx文件转换为pandas库?
【发布时间】:2020-07-23 16:37:40
【问题描述】:

我有一些不典型的情况。我有一个 xlsx excel 文件,其中有 html 代码。如果我将其复制并粘贴到记事本并在浏览器中打开它,它将返回不错的数据库。但是我怎样才能使用代码呢?我想在下一行代码中将它输入到 pandas。

【问题讨论】:

标签: python html excel pandas


【解决方案1】:

您可以保存您的 html 文件,然后使用 BeautifulSoup 从中读取数据。

所以应该是这样的:

url = "C:\example.html"
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

【讨论】:

  • 如何将该文件的内容复制到 html,当我手动复制时仍然出现错误:import urllib2 ModuleNotFoundError: No module named 'urllib2' ' 我已导入:from bs4 import BeautifulSoup import urllib2 '
  • 这是一个更完整的代码,可以帮助您开始解析 HTML,然后将所需的数据添加到 Pandas DF 中。 import pandas as pd import requests # Import the library for sending requests to the server from bs4 import BeautifulSoup # Import the library for webpage parsing URL='.html' req = requests.get(URL) # GET-request soup = BeautifulSoup(req.text, 'lxml')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-30
  • 2022-01-17
  • 1970-01-01
  • 2018-08-02
  • 2015-07-04
相关资源
最近更新 更多