【问题标题】:MATLAB How to Use URLREAD with a Password Protected WebsiteMATLAB 如何在受密码保护的网站上使用 URLREAD
【发布时间】:2014-10-13 22:27:51
【问题描述】:

我正在尝试使用urlread 来获取受密码保护的网站的内容。当我登录时,url是http://media.nba.com/Stats/OfficialBoxScores.aspx,当我退出时,url是http://media.nba.com/Stats/Login.aspx?ReturnUrl=%2fStats%2fOfficialBoxScores.aspx。我试过了

urlread('http://media.nba.com/Stats/OfficialBoxScores.aspx','Username','username','Password','password');

使用我的登录凭据,但它只在登录之前为我提供了 url 的内容。我看到以前有人问过这个问题,但我找不到适合我情况的解决方案。有没有办法使用urlread越过密码保护墙?

任何帮助将不胜感激!

【问题讨论】:

  • 模仿 POST 请求,使用用户名和密码从表单提交数据,使用 cookie 获取响应,将这些 cookie 用于每个进一步的请求。但这不是创建 Matlab 的目的。为什么不使用外部的东西,例如wget
  • 基本上我正在尝试将此代码集成到现有的 MATLAB 脚本中。我是一个 MATLAB 新手,从网络上提取数据的经验更少。可以使用system 函数或其他方式将wget 方法集成到MATLAB 代码中吗?
  • 这不是一种方法——外部控制台程序。这里的主要问题是为每个请求保留和使用 cookie - 它们可能具有将您标识为登录用户的会话 ID。

标签: matlab password-protection urlread


【解决方案1】:

您需要指定method(使用'post'),并且参数需要是名称/值对的元胞数组。

这行得通吗:

urlread('http://media.nba.com/Stats OfficialBoxScores.aspx','post',{'Username','username';'Password','password'} );

【讨论】:

  • 很遗憾没有,它仍在从登录页面提取代码
【解决方案2】:
%Allows you to access url that requires username and password

url_login = 'https://www.your-website-loginpage'
url_data = 'https://www.your-website-data-url'
[stat,h] = web(url_login) %Enter username and password in the popup
setCurrentLocation(h, url_data)
pageText = h.getHtmlText()

【讨论】:

    猜你喜欢
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多