search through text?
|
|
I'm new to greasemonkey and javascript stuff, so bear with me. I've looked through 'dive into greasemonkey' but couldn't find an example of what I need. below is an snippet of a page's html that I am trying to make useful for me. I figured out how to find each link by searching for TITLE's that equal "Document Details..." but now I would like to grab the numbers for the Book and Page (book 22, page 4 in this example). They are in there twice (in the href and as normal page text), but I can't find an example out how get these numbers into variables. Is this possible, or is the coding to old-school? Is there a different way to go about it? < A HREF="/CGI/WWB012/WWM506/R?D=19960112&B=00022&P=004" TITLE="Document Details ...">< SMALL>Book 22< BR>< SMALL>Page< SMALL> 4< R>< /A> Thanks.
|
|
|
This is probably easiest to do with regular expressions. In this example, "thelink" is the link with the title "Document Details ..." in your snippet.
rematches = thelinks.textContent.match(/\s*Book\s*(\d+)\s*Page\s*(\d+)/); book = rematches[1]; page = rematches[2]; |
|
|
I agree that a preview function would be useful. Is there a way to contribute to this site? |
|
|
Jasper: Sure: http://userscripts.devjavu.com/projects/userscr... This forum is based around Beast, so you'd contribute to that, too. I don't feel a need for a preview since posts can be edited. |
|
|
Thanks, that works. Is there a online tutorial that explains the code within the 'match' function? I don't understand it fully. before I get to my next question I need to know if it is possible to link to a file on your own local harddrive? I got the link made with the book and page, but when I click the link, it doesn't open the file. After reading around, I get the impression local file access was removed from greasemonkey for security reasons? or maybe I wrote it out wrong:
(i tried it without the space between 'Book' and '11' and it still didn't work) |
|
|
match documentation can be found at developer.mozilla.org: http://developer.mozilla.org/en/docs/Core_JavaS... Greasemonkey scripts can't read local files but they can create HTML that links to a local file. |
|
|
actually, Firefox itself doesn't link to local files. There is an extension called 'Local Link' you can get that enables it. So I got that part figured out.... |
|
|
ok, whats the best way to get text that occurs on the page before this link that I am processing. basically, it looks like there are going to be a few < td> 's and and < span>'s between this bit of text and the link I'm currently evaluating. This bit of text is inbetween basic bold tags and I can get all the bold tags on the page into an array, but there are more bold tags then link tags - its not 1 to 1. most of these other bold tags have class attributes, so i've been trying to figure out how to just get the plain bold tags so it is 1 to 1 with the links. I think I'll be able to figure that out after more debugging (or you can just tell how to do it ;) ), but it doesn't seem to be a good method and if there is a better way to get this bit of text, please let me know. |
|
|
Well. I have a hard time visualizing the problem from your description without any code snippets, or maybe a link to an example. If you worry about various tags inside the link-tags, don't. Just use the textContent property of the link, and there you have it, all the text inside the link with all the tags stripped out. |
|
|
http://main.co.el-dorado.ca.us/CGI/WWB012/WWM501/R paste this into the search box and submit it: T12N R18E S31
the book and page link is what I am working with. I am trying to grab the 'PARCEL MAP' and 'REC SURVEY' text on the left side each row, as there is book 1 and page 1 (and so forth) for both rec surveys and parcel maps. (the maps themselves are in seperate folders on my hard drive, and I'm trying to add a link to open these files from the webpage). The link itself doesn't have any useful info to differentiate the two.
|
