Using XPATH to isolate inline javascript - Stack Overflow

I'm trying to extract inline javascript that is uniquely different on thousands of URLs, and is ne

I'm trying to extract inline javascript that is uniquely different on thousands of URLs, and is nested within the code at various levels.

As I familiarize myself with XPATH syntax I am trying to see if anyone knows a good way to target javascript For example:

<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_n...</script>
<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_#...</script>

The only unique identfier within the <script>...data_n...</script> that I am attempting to extract is it contains:

var tabsRelated = ...

Within the confines of XPATH does anyone know a way to find the script that contains that variable and target the entire script? Sorta like:

//script[inner.text contains='var tabsRelated'

syntax is not proper

I'm trying to extract inline javascript that is uniquely different on thousands of URLs, and is nested within the code at various levels.

As I familiarize myself with XPATH syntax I am trying to see if anyone knows a good way to target javascript For example:

<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_n...</script>
<script type="text/javascript"> ...data_#...</script>
<script type="text/javascript"> ...data_#...</script>

The only unique identfier within the <script>...data_n...</script> that I am attempting to extract is it contains:

var tabsRelated = ...

Within the confines of XPATH does anyone know a way to find the script that contains that variable and target the entire script? Sorta like:

//script[inner.text contains='var tabsRelated'

syntax is not proper

Share Improve this question edited Nov 7, 2011 at 19:37 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Nov 7, 2011 at 19:27 user856197user856197 3
  • possible duplicate of xpath to get Node containing text – Marc B Commented Nov 7, 2011 at 19:30
  • The question I am asking refers to a more plex problem. In the cited discussion text() seems only to apply to HTML elements. I am unable to use this to isolate the above mentioned inline javascript. – user856197 Commented Nov 7, 2011 at 20:09
  • 1 XPath has no concept of javascript. It's just plain text as far as string searching is concerned. Find JS nodes, and check if their textvalue contains the string you want. – Marc B Commented Nov 7, 2011 at 20:10
Add a ment  | 

1 Answer 1

Reset to default 5

Use:

//script[contains(., $someDistinguishingValue)]

where $someDistinguishingValue should be replaced with the corresponding value (for example the above XPath expression may be dynamically generated as a string and then this string evaluated as an XPath expression using the available XPath API (such as the DOM method SelectNodes() ).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211577a4616872.html

相关推荐

  • Using XPATH to isolate inline javascript - Stack Overflow

    I'm trying to extract inline javascript that is uniquely different on thousands of URLs, and is ne

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信