質問
、私は「テキスト()」または属性値を抽出することができないという問題に遭遇した。
例えば
用
の<のhref = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fstackoverflow.com %22%20および%0Aの%20%20%20%20%20%20xpath%3D '%2F%2Fdiv%2Fh3%2FA' %の0A%20%20%20%20&フォーマット= XML」のrel = "nofollowをnoreferrer">パーマリンクする の
select * from html where url="http://stackoverflow.com"
and xpath='//div/h3/a'
XMLとしてアンカーのリストが表示されます。
<results>
<a class="question-hyperlink" href="/questions/661184/filling-the-text-area-with-the-text-when-a-button-is-clicked" title="In ASP.net, I need the code to fill the text area (in the form) when a button is clicked. Can you help me through by showing a simple .aspx code containing the script tag? ">Filling the text area with the text when a button is clicked</a>...
</results>
今、私が使用してノードの値を抽出しようとすると、
select * from html where url="http://stackoverflow.com"
and xpath='//div/h3/a/text()'
私は、ノードリストではなく、連結の結果を得ます 例えば
<results>Xcode: attaching to a remote process for debuggingWhy is b
…… </results>
私はにはどうすればよいのノードリストに分離し、どのように私はのを選択し、属性値をしますか?
このようなクエリ
select * from html where url="http://stackoverflow.com"
and xpath='//div/h3/a[@href]'
私div/h3/a
解決
YQLはitemPathではなく、ノードのテキストに評価するXPath式が必要です。あなたはitemPathを持っていたら、しかし、あなたは木からさまざまな値を投影することができます。
つまりItemPathはなくテキストコンテンツ/属性より得られたHTML内のノードを指す必要があります。あなたが選択したときYQLがデータから*一致するすべてのノードとその子を返します。
例
select * from html where url="http://stackoverflow.com" and xpath='//div/h3/a'
これは、すべてのAのXPathのマッチングを返します。今のテキストコンテンツを投影する、あなたが使用してそれを投影することができます。
select content from html where url="http://stackoverflow.com" and xpath='//div/h3/a'
「コンテンツ」は、ノード内に保持されたテキストの内容を返します。
の属性を投影するためには、XPath式に比べて、それを指定することができます。このケースでは、と比較しているのhrefを必要とするのでます。
select href from html where url="http://stackoverflow.com" and xpath='//div/h3/a'
このリターン
<results>
<a href="/questions/663973/putting-a-background-pictures-with-leds"/>
<a href="/questions/663013/advantages-and-disadvantages-of-popular-high-level-languages"/>
....
</results>
あなたは属性「のhref」とのTextContentの両方を必要に応じて、その後、次のYQLクエリーを実行することができます:
select href, content from html where url="http://stackoverflow.com" and xpath='//div/h3/a'
戻ります:
<results> <a href="/questions/663950/double-pointer-const-issue-issue">double pointer const issue issue</a>... </results>
お役に立てば幸いです。あなたはYQLに多くの質問がある場合は私に知らせます。