Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the XPATH of Chrome-Console

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to analyze the XPATH of Chrome-Console. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Google browser, as programmers, can be necessary for us at home, and we should be quite familiar with it. What we use most should be the network option, which is generally used to analyze the request information loaded on the web page, such as post parameters. These basic functions are basically enough. Today I am not talking about the network module, but the use of the console command module.

There are also a lot of introductions about the use of console commands on the Internet, but most of them are plagiarized from each other and have no idea who the author is. I'd like to share with you the wonderful use of Google console commands.

I know from the information on the Internet

Currently, the console methods and properties are:

["$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners", "undebug", "monitor", "unmonitor", "table", "$0", "$1", "$2", "$3", "$4", "$_"]

Today we are talking about the $x command.

The usage of $x is: $x (xpath expression) the following example is to get a xpath of adding essays when writing an article.

$x ("/ / div [@ id='Editor_Edit'] / div/span/text ()")

To put it simply, this xpath,// means that no matter how many levels are matched (including the first level), / only one level is matched. The @ symbol indicates that the attribute of the element is followed by the value "Editor_Edit". Looking at the picture above, we find that what is next to the div is still div, and then the next level of div is span. At this point, the xpath can be written like this, / / div [@ id='Editor_Edit'] / div/span.

But what we get is this node of span, the text information is usually in the node, we use text () to get the text of the node, so far we have finished writing, but one thing to note here is that different languages and tools are more or less different when selecting some information about xpath. Let's take a look at the results after we execute xpath.

We found that we got a text node instead of text information. At this time, if you use lxml in python, you can successfully get the text value, but the console needs to take one more step.

Is that we need to get its nodeValue property. Let's write further, and that's it.

$x ("/ / div [@ id='Editor_Edit'] / div/span/text ()") [0]

Let's talk about a little trick here. After we finish writing the above, we will find that we can't point out something when we have some methods. At this time, we can write like this.

Var temp=$x ("/ / div [@ id='Editor_Edit'] / div/span/text ()") [0]

After we get it, we'll see the results. Hey underfined, are you kidding me?

Emmm . . I believe you have encountered similar problems when learning python. The default return value of the method is None. Well, we will know at this time.

This type of situation, never mind the return value, what we need is not this value, after the above operation, what have we done?

Assign the obtained node result to the variable temp, and then temp can exist as a global variable, so let's temp. All at once, I found that many attribute prompts came out.

Ok, the function of this $x is that simple, and it is much more convenient for us to debug.

How to analyze the XPATH of Chrome-Console is shared here. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report