How do I pass a Yahoo Pipes item into a YQL query?

青春壹個敷衍的年華 提交于 2019-12-22 11:35:43

问题


One common thing to want to do in the Yahoo Pipes YQL element is pass in a Pipes value to the YQL query. For example:

select * from html.tostring where url='<someurl>' and xpath='//div[@id="foo"]'

and you want to pass in a dynamic value for <someurl>. Let's say that it's an RSS feed item's URL called item.link. Attempting to simply replace the quoted someurl with item.link gives you this error:

Invalid identifier item.link. me is the only supported identifier in this context

How can I pass this value in?


回答1:


You'll need to create a separate Pipe that takes the item URL as user input, passes it into a string builder which substitues the actual URL value into the YQL query string, and pass that as input to the YQL widget. Then in your main pipe, pass the item.link value as the input to your subpipe.

Specifically:

  1. Create a User inputs -> URL Input item. You can give it any name and prompt. It's helpful to set the "Debug" value for testing.

  2. Create a String builder, with 3 fields. In the first field, put the string up to where the value should be substituted. In the example in the question, select * from html.tostring where url='. In the second field, connect the output from the URL input element to here. In the third field, add the rest of the output: ' and xpath='//div[@id="foo"]'. When the string is built, it will be a complete YQL query string, with the provided URL substituted in.

  3. Create a YQL element, and connect the output from the string builder to the query field.

  4. Connect the YQL elements output to the Pipe Output element.

Save your new pipe.

In your main pipe, create an element of your new pipe (My Pipes -> whatever-you-named-it). Typically you'll be dragging it into a Loop element. Set the input to be item.link and you'll get the proper output.



来源:https://stackoverflow.com/questions/2889406/how-do-i-pass-a-yahoo-pipes-item-into-a-yql-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!