如何在带有 python 的网站上单击 'download as pdf' 按钮
How to click the 'download as pdf' button on a website with python
希望单击此站点上的下载为 pdf 按钮:https://www.goffs.com/sales-results/sales/december-nh-sale-2021/1
我不能只是抓取下载 link 或只是手动下载它的原因是有多个这样的网站:
https://www.goffs.com/sales-results/sales/december-nh-sale-2021/2
https://www.goffs.com/sales-results/sales/december-nh-sale-2021/3
我想遍历所有这些文件并将每个文件下载为 pdf。
当前代码:
导入 urllib.request
从请求导入获取
从 bs4 导入 BeautifulSoup
url = "https://www.goffs.com/sales-results/sales/december-nh-sale-2021/1"
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
此代码应将 link 转换为 pdf:
from urllib.request import *
url = "https://www.goffs.com/sales-results/sales/december-nh-sale-2021/{}".format("1")
request = Request(url)
response = urlopen(request)
content = response.read().decode().split('<a href="https://www.goffs.com/GoffsCMS/_Sales/')
content = content[1].split('"')
content = content[0]
output = 'https://www.goffs.com/GoffsCMS/_Sales/'+content
print(output)
希望单击此站点上的下载为 pdf 按钮:https://www.goffs.com/sales-results/sales/december-nh-sale-2021/1
我不能只是抓取下载 link 或只是手动下载它的原因是有多个这样的网站:
https://www.goffs.com/sales-results/sales/december-nh-sale-2021/2
https://www.goffs.com/sales-results/sales/december-nh-sale-2021/3
我想遍历所有这些文件并将每个文件下载为 pdf。
当前代码: 导入 urllib.request 从请求导入获取 从 bs4 导入 BeautifulSoup
url = "https://www.goffs.com/sales-results/sales/december-nh-sale-2021/1"
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
此代码应将 link 转换为 pdf:
from urllib.request import *
url = "https://www.goffs.com/sales-results/sales/december-nh-sale-2021/{}".format("1")
request = Request(url)
response = urlopen(request)
content = response.read().decode().split('<a href="https://www.goffs.com/GoffsCMS/_Sales/')
content = content[1].split('"')
content = content[0]
output = 'https://www.goffs.com/GoffsCMS/_Sales/'+content
print(output)