简体   繁体   中英

How can I get the anchor (#tag) from an <a> link in tritium?

I am trying to get the anchor tag from an anchor element link in the page eg

<a href="/page#reviews"> 

Is it possible to access the href so I can isolate #reviews and use it elsewhere in my Tritum script?

Thanks!

Yes, it's possible, using a two step process.

First, you can grab the value of the href attribute using the fetch() function.

Then, working on the isolated string, you can use regular expressions to replace all the characters that occur in front of the hash/pound sign ( # ) with a blank.

Here's an example using the Tritium Tester: http://tester.tritium.io/52503bcbe166ca7affa4944d90aae39808c8cd8e .

Note : This assumes that everything after the first # sign in the href attribute is what you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM