{"id":31,"date":"2009-02-11T16:46:55","date_gmt":"2009-02-11T22:46:55","guid":{"rendered":"http:\/\/www.crccheck.com\/blog\/?p=31"},"modified":"2009-08-12T10:19:40","modified_gmt":"2009-08-12T16:19:40","slug":"xpath-to-find-email-address-links","status":"publish","type":"post","link":"https:\/\/www.crccheck.com\/blog\/xpath-to-find-email-address-links\/","title":{"rendered":"Using XPath to find email address links"},"content":{"rendered":"<p>I wanted to write a Greasemonkey script to modify all mailto: links on a page, but to do that, I have to find them first.<\/p>\n<p>Here&#8217;s my first attempt:<\/p>\n<p style=\"padding-left: 30px;\">\/\/a[@href]\/text()[contains(.,&#8221;@&#8221;)]<\/p>\n<p>It&#8217;s pretty bad. I wanted to find links starting with &#8220;mailto:&#8221; but couldn&#8217;t figure out how to operate on the href attribute.<\/p>\n<p>second attempt:<\/p>\n<p style=\"padding-left: 30px;\">\/\/a\/@href[contains(.,&#8221;mailto:&#8221;)]\/..<\/p>\n<p>Here you can see that I managed to operate on the href attribute, and then back back up to the a node. I learned how to select the attribute, instead of using the attribute to select the node.<\/p>\n<p>third attempt:<\/p>\n<p style=\"padding-left: 30px;\">\/\/a[contains(@href,&#8221;mailto:&#8221;)]<\/p>\n<p>Simplified even further!<\/p>\n<p>fourth attempt:<\/p>\n<p style=\"padding-left: 30px;\">\/\/a[starts-with(@href,&#8221;mailto:&#8221;)]<\/p>\n<p>I knew there was a starts with function&#8230; I just had to look it up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to write a Greasemonkey script to modify all mailto: links on a page, but to do that, I have to find them first. Here&#8217;s my first attempt: \/\/a[@href]\/text()[contains(.,&#8221;@&#8221;)] It&#8217;s pretty bad. I wanted to find links starting with &#8220;mailto:&#8221; but couldn&#8217;t figure out how to operate on the href attribute. second attempt: \/\/a\/@href[contains(.,&#8221;mailto:&#8221;)]\/..&hellip;<\/p>\n <a href=\"https:\/\/www.crccheck.com\/blog\/xpath-to-find-email-address-links\/\" title=\"Using XPath to find email address links\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Using XPath to find email address links<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[9,4],"tags":[18],"class_list":["entry","author-admin","post-31","post","type-post","status-publish","format-standard","category-neato","category-technical","tag-xml"],"_links":{"self":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":8,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}