首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从有请求的XHR中抓取数据

从有请求的XHR中抓取数据
EN

Stack Overflow用户
提问于 2019-06-13 19:56:56
回答 1查看 590关注 0票数 0

我想要抓取数据of this website。但我得到的结果与网站上发布的结果不同。例如,当我运行代码时,对于14000和48个月的持续时间,我得到了7.03TAE,而站点上的值是6.44.我认为参数设置错误。有人能帮帮我吗?

我用几种方法改变了参数,但没有起作用。我不知道如何找到合适的参数。

代码语言:javascript
复制
import requests
from bs4 import BeautifulSoup
import re
import json
import pandas as pd

#Let's first collect few auth vars
r = requests.Session()
response = r.get("https://simuladores.bancosantander.es/SantanderES/loansimulatorweb.aspx?por=webpublica&prv=publico&m=100&cta=1&ls=0#/t0")
soup = BeautifulSoup(response.content, 'html')
key = soup.find_all('script',text=re.compile('Afi.AfiAuth.Init'))
pattern = r"Afi.AfiAuth.Init\((.*?)\)"

WSSignature = re.findall(pattern,key[0].text)[0].split(',')[-1].replace('\'','')
WSDateTime = re.findall(pattern,key[0].text)[0].split(',')[1].replace('\'','')

headers = {
    'Origin': 'https://simuladores.bancosantander.es',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
    'Content-Type': 'application/json;charset=UTF-8',
    'Accept': 'application/json, text/plain, */*',
    'WSSignature': WSSignature,
    'Referer': 'https://simuladores.bancosantander.es/SantanderES/loansimulatorweb.aspx?por=webpublica&prv=publico&m=100&cta=1&ls=0',
    'WSDateTime': WSDateTime,
    'WSClientCode': 'SantanderES',
}

#Those are the standard params of a request
params = {'wsInputs': {'finality': 'prestamo coche',
  'productCode': 'p100',
  'capitalOrInstallment': 5000,
  'monthsTerm': 96,
  'mothsInitialTerm': 12,
  'openingCommission': 1.5,
  'minOpeningCommission': 60,
  'financeOpeningCommission': True,
  'interestRate': 5.5,
  'interestRateReferenceIndex': 0,
  'interestRateSecondaryReferenceIndex': 0,
  'interestRateSecondaryWithoutVinculation': 6.5,
  'interestRateSecondaryWithAllVinculation': 0,
  'interestRateSecondary': 6.5,
  'loanDate': '2019-06-13',
  'birthDate': '2001-06-13',
  'financeLoanProtectionInsurance': True,
  'percentageNotaryCosts': 0.003,
  'loanCalculationMethod': 0,
  'calculationBase': 4,
  'frecuencyAmortization': 12,
  'frecuencyInterestPay': 12,
  'calendarConvention': 0,
  'taeCalculationBaseType': 4,
  'lackMode': 0,
  'amortizationCarencyMonths': 0,
  'typeAmortization': 1,
  'insuranceCostSinglePremium': 0,
  'with123': False,
  'electricVehicle': False}}
#The scraping function
def scrape(amount, duration, params):

    params['wsInputs']['capitalOrInstallment'] = amount
    params['wsInputs']['monthsTerm'] = duration
    response = r.post('https://simuladores.bancosantander.es/WS/WSSantanderTotalLoan.asmx/Calculate', headers=headers, data=json.dumps(params))
    return json.loads(response.content)['d']


Amounts = [13000]
Durations = [ 48, 60, 72, 84, 96]
results = []
for amount in Amounts:
    for duration in Durations:
        result = scrape(amount, duration, params)
        result['Amount'] = amount
        result['Duration'] = duration
        results.append(result)

df = pd.DataFrame(results)
EN

回答 1

Stack Overflow用户

发布于 2019-06-13 23:20:21

首先,正如@Richard所说,您的代码没有任何问题。

你得到7.03%而不是6.44%的原因是因为你正在使用的贷款模拟器以某种方式作弊(看起来更具竞争力)。你的不同之处在于对Comisión de apertura金融股的考虑。这意味着如果您将标准参数'openingCommission'设置为0,您将获得6.45%。如果恰好得到6.44%呢?下面是一个建议。

解释(使用法语术语)

如果我计算与超参数{14k欧元,48个月,330.47欧元/米}相关的TEG和TAE,我得到6.26%6.44%

但如果我做同样的计算,包括210欧元的Comisión de apertura金融股,我得到的是~7.03%7.23%

其中i高于(和低于)代表internal rate of return (IRR),即使方程(E1)失效的速率:

这意味着您应该考虑将IRR求解器集成到您的工作流程中,使用可用的信息(菜单、持续时间、总金额甚至费用)来重新计算TAE。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56579958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档