【问题标题】:How to read pdf file directly from github (without downloading or fetching it from github)?如何直接从 github 读取 pdf 文件(无需从 github 下载或获取)?
【发布时间】:2019-12-20 08:31:16
【问题描述】:

我知道我们可以从 pdf 文件中提取文本。

例如,

import pandas as pd
import PyPDF2

# =============================================================================
# Extracting from pdf files
# =============================================================================
pdfFileObj = open(r'C:\Users\User\Documents\Sentiment_Analysis\Urea Weekly Report 01-07-2016.pdf', 'rb')

pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
totalpage = pdfReader.numPages

pg = [''] * (totalpage-2-2)
for i in [x for x in range(2,totalpage-2) if x != 7]:
    pageObj = pdfReader.getPage(i)
    pg[i-2] = pageObj.extractText().replace("\n","").lower()

我该如何做类似的事情,但现在 pdf 文件驻留在 github 中?

我知道我们可以使用 excel 文件(无需下载)来做到这一点

import pandas as pd
meg = pd.read_csv('https://raw.githubusercontent.com/James-smarttradz/arimax/master/MEG_marketprice_ICIS.csv')

例如,我的文件位于 https://github.com/James-smarttradz/sentiment/blob/master/Urea%20Weekly%20Report%2001-07-2016.pdf

【问题讨论】:

  • 你看过像requests 这样的库来获取文件吗?
  • 嗨 Oliver,我知道我可以获取或下载文件并完成上述操作,我想知道我是否可以直接对 pdf 文件执行操作,而无需像类似的那样获取或下载它上面的excel代码。

标签: python pdf github pypdf2


【解决方案1】:

您可以先下载此 pdf 文件:

 import wget
    url = "https://github.com/James-smarttradz/sentiment/blob/master/Urea%20Weekly%20Report%2001-07-2016.pdf"
    wget.download(url, 'C:\Users\User\Documents\Sentiment_Analysis\Urea Weekly Report 01-07-2016.pdf')

然后继续你之前的代码进行必要的操作

【讨论】:

  • 谢谢Ahmed,我知道我可以下载文件并完成上面的操作,我想知道我是否可以直接在github上的pdf文件上执行操作,而无需像代码那样获取或下载它对于上面的excel。
猜你喜欢
  • 1970-01-01
  • 2019-01-23
  • 2021-11-22
  • 2012-02-05
  • 2021-04-17
  • 2016-01-09
  • 2013-04-16
  • 2021-10-28
相关资源
最近更新 更多