首页 > 解决方案 > 如何使用 Python 通过按钮下载 csv?

问题描述

这是链接,我想通过设置商品的最大日期范围来下载 csv: https ://www.investing.com/commodities/gold-historical-data

我怎样才能用 Python 做到这一点?我有网页但不知道如何下载 csv(

import requests
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

# Fill in your details here to be posted to the login form.
payload = {
    'loginFormUser_email': 'email',
    'loginForm_password': 'password'
}



proxies = {
  'http': 'http://user:passw@proxy:9090',
  'https': 'http://user:passw@proxy:port'
}

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}


# Use 'with' to ensure the session context is closed after use.
with requests.Session() as s:

    r1 = s.get('https://ru.investing.com/', stream=True, verify=False, proxies=proxies, headers=headers)
    print(r1.status_code) --200

    r2 = s.get('https://ru.investing.com/members-admin/auth/getSignInPopUp', stream=True, verify=False, proxies=proxies, headers=headers)
    print(r2.status_code) --200

    # An authorised request.
    r3 = s.post('https://ru.investing.com/members-admin/auth/signInByEmail/', stream=True, verify=False, proxies=proxies, headers=headers, data=payload)
    print(r3.status_code) --200


    r4 = s.get('https://ru.investing.com/commodities/gold-historical-data', stream=True, verify=False, proxies=proxies, headers=headers)
    print(r4.status_code) -200

标签: pythonpython-requests

解决方案


推荐阅读