2009-03-19 19 views
10

का उपयोग कर एचटीएमएल क्वेरी करना YQL क्वेरी भाषा और YQL द्वारा प्रदान की गई xpath कार्यक्षमता का उपयोग करके एचटीएमएल को पार्स करने का प्रयास करते समय, मैं "टेक्स्ट()" या विशेषता मान निकालने में सक्षम नहीं होने की समस्याओं में भाग गया।
उदाहरण के लिए
perma linkयाहू YQL

select * from html where url="http://stackoverflow.com" 
and xpath='//div/h3/a' 

जब मैं

select * from html where url="http://stackoverflow.com" 
and xpath='//div/h3/a/text()' 

मैं परिणाम एक के बजाय concatenated मिल का उपयोग कर नोड मान प्राप्त करने के लिए प्रयास करें एक्सएमएल के रूप में एंकर की एक सूची देता है

<results> 
    <a class="question-hyperlink" href="https://stackoverflow.com/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> 

अब नोड सूची उदाहरण के लिए

<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

उत्तर

20

YQL के लिए दिया एक ही परिणाम एक itemPath बल्कि नोड पाठ से मूल्यांकन करने के लिए xpath एक्सप्रेशन की आवश्यकता है। लेकिन एक बार जब आपके पास कोई आइटमपैथ हो तो आप पेड़ से विभिन्न मूल्यों को प्रोजेक्ट कर सकते हैं

दूसरे शब्दों में एक आइटमपैथ को टेक्स्ट सामग्री/विशेषताओं के बजाय परिणामी HTML में नोड को इंगित करना चाहिए। जब आप डेटा से * चुनते हैं तो YQL सभी मेल खाने वाले नोड्स और उनके बच्चों को लौटाता है।

उदाहरण

select * from html where url="http://stackoverflow.com" and xpath='//div/h3/a' 

यह रिटर्न एक के xpath मिलान सब। अब पाठ सामग्री प्रोजेक्ट करने के लिए आप इसे

select content from html where url="http://stackoverflow.com" and xpath='//div/h3/a' 

"सामग्री" नोड के भीतर रखी गई टेक्स्ट सामग्री को वापस कर सकते हैं।

गुणों को प्रक्षेपित करने के लिए, आप इसे xpath अभिव्यक्ति के सापेक्ष निर्दिष्ट कर सकते हैं। इस मामले में, चूंकि आपको उस href की आवश्यकता है जो ए के सापेक्ष है।

select href, content from html where url="http://stackoverflow.com" and xpath='//div/h3/a' 

रिटर्न:

<results> <a href="https://stackoverflow.com/questions/663950/double-pointer-const-issue-issue">double pointer const issue issue</a>... </results> 

select href from html where url="http://stackoverflow.com" and xpath='//div/h3/a' 

इस रिटर्न <results> <a href="https://stackoverflow.com/questions/663973/putting-a-background-pictures-with-leds"/> <a href="https://stackoverflow.com/questions/663013/advantages-and-disadvantages-of-popular-high-level-languages"/> .... </results>

तुम दोनों विशेषता की 'href' और textContent की जरूरत है, तो आप निम्नलिखित YQL क्वेरी निष्पादित कर सकते हैं

आशा है कि मदद करता है। अगर आपको YQL पर अधिक प्रश्न हैं तो मुझे बताएं।

+0

एक आकर्षण की तरह काम करता है! – Cherian

संबंधित मुद्दे