使用Python的请求登录FT.com [英] Log Into FT.com with Python's requests

查看:221
本文介绍了使用Python的请求登录FT.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,该脚本将登录我的FT.com帐户并为我提取一些数据。

I'm trying to write a script which will log into my FT.com account and pull down some data for me.

第一个障碍显然是登录。我正在使用Pythons Requests库。

The first hurdle is obviously logging in. I'm using Pythons Requests library for this.

这是我的代码:

#!/usr/bin/env python
import requests


# log into FT website
log_in_url = 'https://accounts.ft.com/login'
my_email = 'my@emaill.com'
my_pass = 'mypassword'
data = {'email': my_email,
        'password': my_pass,
}

with requests.Session() as session:
    log_in_request = session.post(log_in_url, data=data)
    # prints log-in page with error about contacting cus. service
    print log_in_request.content

它只是将我重定向回登录页面。它没有说'不正确的细节'或任何东西(它们肯定是正确的)。它只是不允许我登录。我怀疑我的POST请求有问题 - 比如我缺少标题或cookie或其他东西。

It just redirects me back to the login page. It doesn't say 'incorrect details' or anything (they're definitely correct). It just won't let me log in. I suspect something is wrong with my POST request - like I'm missing headers or cookies or something.

任何人都知道什么可能继续?

Anybody know what might be going on?

干杯,

Dean

推荐答案

如果您复制原始内容或从ft网站上删除不可忽略的数据量,您将被正确地阻止,因为您将违反其T& Cs(更不用说版权法)。

If you copy original content or scrape non-negligible amounts of data from the ft website, you will rightly be blocked as you will be violating their T&Cs (not to mention copyright law).

英国金融时报的部分资金来自广告。如果你通过使用Python来绕过这些,你就会侵蚀一个合理的收入来源。

The FT is partly funded by advertisements. If you bypass these by using Python you are eroding a legimitimate revenue source.

我使用这个脚本将我的监视列表拉入Excel,我以前使用复制/粘贴做。我不会将它用于分析或阅读文章。我通过浏览器阅读FT,每天产生相当程度的广告查看流量。

I use this script to pull my watchlists into Excel, which I used to do using copy/paste. I do not use it for analytics or to read articles. I read the FT via the browser generating a fair degree of advert-viewing traffic daily.

请不要滥用此功能。如果这样做,很可能会导致每个付费用户被阻止在Python中进行少量导航。

Please do not abuse this. If you do, it is likely to result in every paying subscriber being blocked from doing even tiny amounts of navigating in Python.

from robobrowser import RoboBrowser

browser = RoboBrowser(history=True)

url='https://accounts.ft.com/login?location=https%3A%2F%2Fwww.ft.com%2F'

browser.open(url)
form=browser.get_form()
form['email']=""
form['password']=""
browser.session.headers['Referer'] = url
browser.submit_form(form)

如果您希望执行Datamining等,则有一个FT开发人员计划:
https://developer.ft.com/

There is an FT Developer Programme if you wish to perform Datamining and so on: https://developer.ft.com/

这篇关于使用Python的请求登录FT.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆