【发布时间】:2021-12-30 11:25:02
【问题描述】:
我有大约 900 页,每页包含 10 个按钮(每个按钮都有 pdf)。我想下载所有的 pdf - 程序应该浏览到所有页面并一一下载 pdf。
仅搜索 .pdf 的代码,但我的 href 没有 .pdf page_no(1 到 900)。
https://bidplus.gem.gov.in/bidlists?bidlists&page_no=3
这是网站,下面是链接:
投标编号:GEM/2021/B/1804626import os
import requests
from urllib.parse import urljoin
from bs4 import BeautifulSoup
url = "https://bidplus.gem.gov.in/bidlists"
#If there is no such folder, the script will create one automatically
folder_location = r'C:\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)
【问题讨论】:
-
好的答案需要好的问题,请通过改进您的问题来帮助大家理解您的问题 --> 您之前的尝试是什么样的,您在哪里没有得到进一步的帮助?谢谢
-
已编辑请检查@HedgeHog
-
您的网站是否仅在印度可用?
-
如果您完全不知道它是如何工作的,this post 可能会帮助您 - 关键是我们很乐意帮助您解决您遇到的特定问题,但我们没有您以前的尝试,无法编织现成的解决方案。
-
抱歉,这只是我发布的链接中接受的答案的副本 - 这种行为不好,没有表现出任何努力 - 我出去了
标签: python beautifulsoup