当前位置:网站首页>One night I worked as an XPath Terminator: XPath Helper Plus
One night I worked as an XPath Terminator: XPath Helper Plus
2022-06-25 18:59:00 【Pan senmi】
Preface
As a senior 『xpath』 Extraction Engineer , Want to get data from the page quickly , There must be some tools ,
And the first contact is xpath-helper
This browser plug-in . After a period of use , It is found that the author has some special needs , I want to expand on this basis .
So I learned how to develop chrome plug-in unit ? How to use your own attributes vue To develop ? After a two-day weekend 、gayhub After understanding , With such a tool .
problem
xpath-helper2.0.2 Native is to support pressing and holding shift Then use the mouse to locate and select the element , And the output xpath grammar , But in this way xptah Grammar is not friendly .
For example, I want to pick up the title of an article about nuggets :
/html/body/div[@id=‘__nuxt’]/div[@id=‘__layout’]/div[@id=‘juejin’]/div[@class=‘view-container container’]/main[@class=‘container main-container with-view-nav’]/div[@class=‘view timeline-index-view’]/div[@class=‘timeline-container’]/div[@class=‘timeline-content’]/aside[@class=‘index-aside aside’]/div[@class=‘signin-tip signin’]/div[@class=‘first-line’]/button[@class=‘btn signin-btn’]/span[@class=‘btn-text’]
It came out one xpath grammar , This xpath Grammar comes from DOM The root node starts to go down one by one ( The source code is from bottom to top ) To put together . This will become very redundant .
Although it can accurately locate the elements we want , But once you put this xpath The syntax is copied into the code , It's terrible .
Of course, some programmers are keen to choose to use chrome The original elements are copied into xpath.
The result is :
//*[@id=“juejin”]/div[1]/main/div/div/div/aside/div[1]/div[1]/button/span
Obviously, the above two schemes have their own problems : Grammatical redundancy 、 No readability .
solve
The solution given by the author is in xpath-helper On the basis of , Add an auxiliary function , It maximizes streamlining xpath grammar , Once it is found that its syntax can recognize the element, it will not continue to look up . It's about returning immediately .
//span[@class=‘btn-text’]
And it can also be friendly to css Selector syntax :
span.btn-text
We can do it in chrome Check this syntax in the element of :
- xpath:
- css:
Realization
xpath-helper-plus Its core API All come from xpath-helper.
On this basis, the author adds some additional functions , such as : Streamlining xpath sentence 、 conversion CSS Selectors .
With the original xpath helper The difference is , This time, chrome The plug-in uses Vue3+vite To develop , Component oriented , adopt vite Pack it up chrome File directory structure of plug-in specification .
More functions may be provided in the future . Or develop other plug-ins on this basis .
Open source
边栏推荐
- SVN介绍及使用总结
- On location and scale in CNN
- shell-跳出循环-shift参数左移-函数的使用
- 【ELT.ZIP】OpenHarmony啃论文俱乐部—见证文件压缩系统EROFS
- Training of long and difficult sentences in postgraduate entrance examination day91
- MySQL view explanation
- Analysis on development scale and development trend of China's night economy industry in 2021 [figure]
- [in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
- QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]
- 揭秘GES超大规模图计算引擎HyG:图切分
猜你喜欢
初探Oracle全栈虚拟机---GraalVM
Analysis on development status and development suggestions of e-commerce industry in Xinjiang in 2020 [figure]
Analysis of global tea production, consumption and import and export trade: China's tea production ranks first in the world [figure]
Analysis on employment compensation of 2021 college graduates: the average monthly starting salary of doctors, masters, undergraduates and junior colleges is 14823 yuan, 10113 yuan, 5825 yuan and 3910
[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance
Kotlin Compose 终结toDo项目 点击可以编辑修改todo
Detailed explanation of oauth2 - Introduction (I)
焕新出发,利尔智达天下
[in depth understanding of tcapulusdb technology] tcapulusdb model
【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用
随机推荐
In 2021, China's private equity market is growing, and the scale of private equity fund management reaches 19.78 trillion yuan [figure]
TCP/IP 测试题(三)
158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
为什么生命科学企业都在陆续上云?
Regular expression summary
mysql视图讲解
How to sort massive data? How to process data between memory and hard disk?
正则表达式总结
Training of long and difficult sentences in postgraduate entrance examination English Day82
Shell jump loop shift parameter left use of function
跳一跳小游戏辅助(手动版本)py代码实现
Svn introduction and Usage Summary
Redis6
MySQL view explanation
LeetCode 322. Change exchange & dynamic planning
JS some small problems about adding and accessing values to arrays
GenICam GenTL 标准 ver1.5(1)
【ELT.ZIP】OpenHarmony啃论文俱乐部—数据密集型应用内存压缩
Analysis on the market scale and pattern of contrast agents in China in 2021: Jiangsu Hengrui pharmaceutical, general electric, Yangzijiang Pharmaceutical Group, Bayer and bleco account for more than
Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)