从Controller中使用EmberJS transitionToRoute时,如何更正URL路径中的[object%20Object]?(How do I correct [object%20Object] in URL path when using EmberJS transitionToRoute from Controller?)
我正在尝试在模板中设置一个动作,根据动态生成的导航栏将用户转换到另一个路径,使用客户端执行的json /和js的组合。 我已经设法配置我的应用程序,以便我可以生成有效的常规路径,但我想使用转换来避免额外的页面加载。
对(希望)必要信息的要点是:
https://gist.github.com/rjfranco/5289201
JS:
App.Router.map -> @route 'index', {path: "/#{short_name}"} @route 'customList', {path: "/#{short_name}/custom-list/:list_name"} @route 'multiLevelList', {path: "/#{short_name}/multi-level-list/:list_name/:list_level"} App.EventController = Em.ObjectController.extend goTo: (navbar_icon) -> @transitionToRoute navbar_icon.route, navbar_icon.context # Sample passed navbar_icon navbar_icon = img_src: '/somesource_or_another.jpg' display_name: 'My Link Name!' route: 'customList' context: {list_name: 'Exhibitors'}
模板:
{{#each controller.navbarIcons}} <li><a {{action goTo this}}><img {{bindAttr src="image_src"}} width="36" height="36" />{{display_name}}</a></li> {{/each}}
预期页面实际上加载正常,但应用程序转换到的URL不正确,刷新会破坏应用程序。
我期待一个URL:
/ruhaha/custom-list/Exhibitors
我最终得到一个像:/ruhaha/custom-list/[object%20Object]
稍微更新:我发现我可以在应用程序上滥用几种方法来产生我想要的结果:
App.handleURL('/ ruhaha /定制列表/展商)
App.Router.router.replaceURL('/ ruhaha /定制列表/展商)这实际上会触发路由,并且在没有页面请求的情况下替换有效地将我的应用程序转换到我想要的状态的URL。 虽然这有效但我很确定这是解决这个问题的错误方法。
I'm attempting to setup an action in a template to transition users to another route based on a dynamically generated navbar, using a combination of json / and js that is executed client side. I've managed to configure my application so that I can generate regular paths that work, but I would like to use transitions to avoid additional page loads.
A gist with what is (hopefully) the necessary information is:
https://gist.github.com/rjfranco/5289201
JS:
App.Router.map -> @route 'index', {path: "/#{short_name}"} @route 'customList', {path: "/#{short_name}/custom-list/:list_name"} @route 'multiLevelList', {path: "/#{short_name}/multi-level-list/:list_name/:list_level"} App.EventController = Em.ObjectController.extend goTo: (navbar_icon) -> @transitionToRoute navbar_icon.route, navbar_icon.context # Sample passed navbar_icon navbar_icon = img_src: '/somesource_or_another.jpg' display_name: 'My Link Name!' route: 'customList' context: {list_name: 'Exhibitors'}
template:
{{#each controller.navbarIcons}} <li><a {{action goTo this}}><img {{bindAttr src="image_src"}} width="36" height="36" />{{display_name}}</a></li> {{/each}}
The expected page actually loads fine, but the url the application transitions to is not correct, and refreshing breaks the application.
I'm expecting a URL along the lines of:
/ruhaha/custom-list/Exhibitors
and I end up with one like:/ruhaha/custom-list/[object%20Object]
Slight update: I've found that I could abuse a couple of methods on the app to produce the results I want:
App.handleURL('/ruhaha/custom-list/Exhibitors')
App.Router.router.replaceURL('/ruhaha/custom-list/Exhibitors')This will actually trigger the route, and replace the url effectively transitioning my application to the state I want without a page request. Although this works I'm pretty certain this is the wrong way to take care of this issue.
原文:https://stackoverflow.com/questions/15768218
最满意答案
如果我是你,我
find_all()
类名作为参数传递给find()
函数而不是find_all()
,我首先要查找包含你正在寻找的锚的<li>
元素。 它看起来像这样from bs4 import BeautifulSoup import requests username='justinbieber' url = 'https://www.twitter.com/'+username r = requests.get(url) soup = BeautifulSoup(r.content) f = soup.find('li', class_="ProfileNav-item--followers") title = f.find('a')['title'] print title # 81,346,708 Followers num_followers = int(title.split(' ')[0].replace(',','')) print num_followers # 81346708
PS
findAll()
find_all()
在bs4中被重命名为find_all()
If I were you, I'd be passing the class name as an argument to the
find()
function instead offind_all()
and I'd first look for the<li>
element that contains the anchor you're loooking for. It'd look something like thisfrom bs4 import BeautifulSoup import requests username='justinbieber' url = 'https://www.twitter.com/'+username r = requests.get(url) soup = BeautifulSoup(r.content) f = soup.find('li', class_="ProfileNav-item--followers") title = f.find('a')['title'] print title # 81,346,708 Followers num_followers = int(title.split(' ')[0].replace(',','')) print num_followers # 81346708
PS
findAll()
was renamed tofind_all()
in bs4
相关问答
更多-
是否有可能获得当前的Twitter总人数?(Is it possible to get the current total Twitter followers number? and how often?)[2022-11-06]
你好对不起,我不知道PHP很好,而且根本不是JQuery,但是,这是我在C#中完成的工作......希望它有帮助;) // Launch the request to obtain the number of followers of the user WebRequest request = HttpWebRequest.Create("http://twitter.com/users/show.xml?screen_name=[username]"); using (HttpWebResponse r ... -
下面是一些示例代码,基于您在原始问题中的内容,它将聚合一组用户的Twitter结果: # create a data frame with 4 columns and no rows initially df_result <- data.frame(t(rep(NA, 4))) names(df_result) <- c('id', 'name', 's_name', 'fol_count') df_result <- df_result[0:0,] # you can replace this vec ...
-
使用BeautifulSoup从Twitter中提取追随者数量(Extract Number of Followers from Twitter using BeautifulSoup)[2023-03-25]
如果我是你,我find_all()类名作为参数传递给find()函数而不是find_all() ,我首先要查找包含你正在寻找的锚的- 元素。 它看起来像这样 from bs4 import BeautifulSoup import requests username='justinbieber' url = 'https://www.twitter.com/'+username r = requests.get(url) soup = BeautifulSoup(r.content) f = soup ...
-
正如您现在必须学习的那样,速率限制和计数限制会阻止Twitter API上的大量操作。 有了这些限制,大多数答案都不够充分,但这是我将使用的一般方法: 使用“ 列表关注者”查询获取所有关注者ID的列表 。 确保最大数量为5000,以减少查询次数。 如果您的用户拥有数十万(甚至数百万)的关注者,这不是最佳选择,但仍然是最有效的选择。 使用该列表,您可以执行查询用户详细信息查询。 此处的情况更糟糕,因为逗号分隔的用户ID的最大数量为100.您可以考虑跟踪UserID以按上次扫描的活动/日期对其进行分类,以避免重 ...
-
获取Twitter粉丝数量(Get Twitter Followers number)[2022-03-23]
在版本1.1中,您必须创建一个Twitter应用程序,然后使用oauth_token,oauth_token_secret,oauth_consumer_key,oauth_consumer_secret值来调用REST API。 请参阅以下文章。 他们用代码解释如何连接到Twitter并获取所需的详细信息。 http://aspxdeveloper.blogspot.com.au/2013/06/twitter-api-11-example-on-c-asp-dot-net.html https://um ... -
这是一个奇怪的。 我写了代码,应该拉数字,但它也一直返回null 。 我终于弄清楚当我拉出元素然后写出outerHTML时发生了什么。 页面加载期间正在更改元素。 WebDriver driver = new FirefoxDriver(); driver.get("https://twitter.com/blakeshelton"); WebDriverWait wait = new WebDriverWait(driver, 5); WebElement e = wait.until(ExpectedC ...
-
您无需获取所有用户关注者以便对其进行计数。 使用followers_count属性。 例如: import tweepy auth = tweepy.OAuthHandler(..., ...) auth.set_access_token(..., ...) api = tweepy.API(auth) for user in tweepy.Cursor(api.followers, screen_name="twitter").items(): print user.screen_name, ...
-
$.ajax({ url: 'http://api.twitter.com/1/users/show.json', data: {screen_name: ''}, dataType: 'jsonp', success: function(data) { $('#twitter ...
-
要使用屏幕名称检索给定用户的关注者,请参阅Twitter#getFollowersList() ,例如: long cursor = -1; PagableResponseList
followers; do { followers = twitter.getFollowersList("screenName", cursor); for (User follower : followers) { // TODO: Collect top 10 follower ... -
这段代码对我来说很好: #!/usr/bin/env python import requests from json import loads username = "liamgiannini" r = requests.get('https://www.instagram.com/'+username) html = r.text.encode("utf-8") text = html[html.index("window._sharedData = ")+21:] text = (text[:t ...