有没有办法在控制器中获取URL的锚点部分?
示例:如果我键入http://www.foo.com/bar#anchor123,我可以在控制器中获取字符串anchor123吗?
在我的Phoenix应用程序中,我想向URL添加查询字符串:
some_cool_path(@conn, :index, "view-mode": "table")
Run Code Online (Sandbox Code Playgroud)
我希望它会生成类似的URL /some_cool?view-mode=table,但会引发异常:
protocol Phoenix.Param not implemented for ["view-mode": "table"]
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我正在使用请求来编译自定义 URL,并且一个参数包含一个井号。谁能解释如何在不编码井号的情况下传递参数?
这将返回正确的 CSV 文件
results_url = 'https://baseballsavant.mlb.com/statcast_search/csv?all=true&hfPT=&hfAB=&hfBBT=&hfPR=&hfZ=&stadium=&hfBBL=&hfNewZones=&hfGT=R%7C&hfC=&hfSea=2019%7C&hfSit=&player_type=batter&hfOuts=&opponent=&pitcher_throws=&batter_stands=&hfSA=&game_date_gt=&game_date_lt=&hfInfield=&team=&position=&hfOutfield=&hfRO=&home_road=&hfFlag=&hfPull=&metric_1=&hfInn=&min_pitches=0&min_results=0&group_by=name&sort_col=pitches&player_event_sort=h_launch_speed&sort_order=desc&min_abs=0&type=#results'
results = requests.get(results_url, timeout=30).content
results_df = pd.read_csv(io.StringIO(results.decode('utf-8')))
Run Code Online (Sandbox Code Playgroud)
这不
URL = 'https://baseballsavant.mlb.com/statcast_search/csv?'
def _get_statcast(params):
_get = get(URL, params=params, timeout=30)
_get.raise_for_status()
return _get.content
Run Code Online (Sandbox Code Playgroud)
问题似乎是,当通过请求传递 '#results' 时,'#' 被忽略后会导致下载错误的 CSV。如果有人对解决此问题的其他方式有任何想法,我将不胜感激。
EDIT2:也在python论坛上问过这个https://python-forum.io/Thread-Handling-pound-sign-within-custom-URL?pid=75946#pid75946