此处显示的web抓取代码给出以下错误:
解压缩数据时出现错误-3:错误的标头检查
为什么以及如何修复它?
import urllib.request
import zipfile
import pandas as pd
from bs4 import BeautifulSoup
import requests
import os
head = {'Accept-Encoding': 'gzip'}
BHAVCOPY_URL = "https://www.bseindia.com/markets/MarketInfo/BhavCopy.aspx"
html = requests.get(BHAVCOPY_URL, headers=head)
In [36]: headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gec
...: ko) Chrome/83.0.4103.97 Safari/537.36"}
In [37]: import urllib.request
...: import zipfile
...: import pandas as pd
...: from bs4 import BeautifulSoup
...: import requests
...: import os
...:
...: BHAVCOPY_URL = "https://www.bseindia.com/markets/MarketInfo/BhavCopy.aspx"
...: html = requests.get(BHAVCOPY_URL, headers=headers)