在选择“HK Stock”和“Show All”按钮后,我尝试在“https://www.bsgroup.com.hk/BrightSmart/MarginRatio/StockMarginRatioEnquiry.aspx?Lang=eng”中下载该表。我检查了Chrome/Inspect/Network功能。没有向服务器发送新数据的请求。因此,我怀疑数据在原始页面中。按下“全部显示”按钮后,我检查了它是否出现在“表1”中。我尝试了以下代码,但没有结果,请告知:
url="https://www.bsgroup.com.hk/BrightSmart/MarginRatio/StockMarginRatioEnquiry.aspx?Lang=eng"
result = requests.get(url)
result.raise_for_status()
result.encoding = "utf-8"
src = result.content
soup = BeautifulSoup(src, 'lxml')
table = soup.findAll("Table1")
output_rows = []
for table_row in table.findAll('tr'):
columns = table_row.findAll('td')
output_row = []
for column in columns:
output_row.append(column.text)
output_rows.append(output_row)
print(output_rows)
要获取数据,必须使用正确的参数发出
POST
请求例如:
印刷品:
编辑:要写入CSV文件,可以使用以下示例:
相关问题 更多 >
编程相关推荐