python - 自动下载多个 pdf 文件中的所有链接(PDF)
问题描述
我正在尝试从网站 ( http://cis-ca.org/islamscience1.php ) 下载期刊问题。我跑了一些东西来获取此页面上的所有 PDF。然而,这些 PDF 内部有链接到另一个 PDF 的链接。
我想从所有 PDF 链接中获取终端文章。
从页面获取所有 PDF:http: //cis-ca.org/islamscience1.php
import os
import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup
url = "http://cis-ca.org/islamscience1.php"
#If there is no such folder, the script will create one automatically
folder_location = r'webscraping'
if not os.path.exists(folder_location):os.mkdir(folder_location)
response = requests.get(url)
soup= BeautifulSoup(response.text, "html.parser")
for link in soup.select("a[href$='.pdf']"):
#Name the pdf files using the last portion of each link which are unique in this case
filename = os.path.join(folder_location,link['href'].split('/')[-1])
with open(filename, 'wb') as f:
f.write(requests.get(urljoin(url,link['href'])).content)
我想在这些 PDF 中链接文章。提前致谢
解决方案
https://mamclain.com/?page=Blog_Programing_Python_Removing_PDF_Hyperlinks_With_Python
看看这个链接。它展示了如何识别超链接和清理 PDF 文档。您可以将其跟踪到标识部分,然后执行存储超链接而不是清理的操作。
或者,看看这个库:https ://github.com/metachris/pdfx
推荐阅读
- postgresql - Rust sqlx:没有查询终结器
- python - 如何在pygame中只播放一次鼠标悬停音效?
- idl-programming-language - 以度而不是弧度绘制
- sql - 组合并计算火花数据框中的 json 列
- node.js - Discord.js - 将文件发送到 PC 上的文件夹
- conditional-statements - 有条件的 FLEX/BISON 代码生成可能吗?
- list - 如何用原始格式写出列表变量
- visual-studio-code - VS 代码终端选项卡颜色
- python - 为什么这个列表元素会在列表中移回?
- java - Java Swing DrawRect:创建新维度替换旧维度