Код: Выделить всё
import pandas as pd
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable insecure certificate warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Load the list of numbers from Excel
df = pd.read_excel('prospectos_numero.xlsx')
# Setting the header
headers = {'User-Agent': 'Mozilla/5.0'}
# Click on each number in the list and download the corresponding document
for number in df['ID_num']: # Replace 'numbers' with the name of the column in your Excel file
url = f'https://fnet.bmfbovespa.com.br/fnet/publico/downloadDocumento?id={number}'
response = requests.get(url, headers=headers, verify=False)
if response.status_code == 200 and response.headers['Content-Type'] == 'application/pdf':
with open(f'{number}.pdf', 'wb') as file:
file.write(response.content)
print(f'Document {number} downloaded with success.')
else:
print(f'Failed to download {number}. Status code: {response.status_code}, Type of content: {response.headers["Content-Type"]}')
Код: Выделить всё
import base64
import pandas as pd
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Disable insecure certificate warnings
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# Load the list of numbers from Excel
df = pd.read_excel('prospectos_numero.xlsx')
# Setting the header
headers = {'User-Agent': 'Mozilla/5.0'}
# Click on each number in the list and download the corresponding document
for number in df['ID_num']: # Replace 'ID_num' with the name of the column in your Excel file
url = f'https://fnet.bmfbovespa.com.br/fnet/publico/downloadDocumento?id={number}'
response = requests.get(url, headers=headers, verify=False)
if 'Content-Disposition' in response.headers:
print('Content-Disposition:', response.headers['Content-Disposition'])
filename = response.headers['Content-Disposition'].split('filename=')[-1].strip('"')
print('filename:', filename)
content = base64.b64decode(response.content)
if response.status_code == 200 and response.headers['Content-Type'] == 'application/pdf':
with open(f'{number}.pdf', 'wb') as file:
file.write(response.content)
print(f'Document {number} downloaded with success.')
else:
print(f'Failed to download {number}. Status code: {response.status_code}, Type of content: {response.headers["Content-Type"]}')
Подробнее здесь: https://stackoverflow.com/questions/790 ... -wont-open