正则表达式解决方案,无法访问以前易于访问的nba STATS网址

时间:2016-11-28 16:39:27

标签: html url

这可能稍微偏离主题,但由于解决方案是一般表达式问题,我认为在这里解决它可能会很有趣。

我正在尝试访问包含我通常用于分析的数据的网址:

http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2011-12&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2011-12&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0

正如您在网址中看到的那样,它有许多字段需要填充,而此以前工作过的网址会给我以下错误:

The PlayerPosition property is required.

所以我认为,如果我添加了

,就像URL中的许多其他字段一样
&PlayerPosition=0

它会使用每个位置,所以我使用了这个网址:

http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2011-12&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2011-12&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition=0

但它给了我以下错误:

The field PlayerPosition must match the regular expression '^((Guard)|(Center)|(Forward))?$'.

所以我尝试将& PlayerPosition = 0替换为:

&PlayerPosition=&PlayerPosition='^((Guard)|(Center)|(Forward))?$'

&PlayerPosition=&PlayerPosition= ^((Guard)|(Center)|(Forward))?$

&PlayerPosition=&PlayerPosition=((Guard)|(Center)|(Forward))?

&PlayerPosition=&PlayerPosition=((Guard)|(Center)|(Forward))

但没有任何效果,它给了我同样的错误,任何建议?

2 个答案:

答案 0 :(得分:1)

玩家位置应与此正则表达式匹配:

'^((Guard)|(Center)|(Forward))?$'

()?表示括号之间的所有内容都是可选的。因此,(Guard)|(Center)|(Forward)是可选的。 可以为空白

表示以下值均有效:

  • PlayerPosition =保护
  • PlayerPosition =中心
  • PlayerPosition =转发
  • PlayerPosition =

我已经尝试在浏览器中使用它,之后没有任何操作并且有效:

http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2011-12&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2011-12&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition=

答案 1 :(得分:0)

在任何地方添加参数PlayerPosition你的url字符串。但价值只能是“警卫”或“中心”或“前进”。

例如

http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2011-12
  &ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=
  &LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0
  &OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame
  &Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=
  &Season=2011-12&SeasonSegment=&SeasonType=Regular+Season&TeamID=0
  &VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1
  &showZones=0
  &PlayerPosition=Guard