Jump to content

Parsing syntax in a match statement


dirkcurious

Recommended Posts

Hello, I am attempting to use the following;

document.location.href.match(/officer\.aspx\?cmp=1\&ofn=[A-Z][0-9][0-9][0-9][0-9][0-9]/g)to parse the url of; http://xxxxxxxx.com/officer.aspx?cmp=1&ofn=G64665 (for example)

I am unsure if I am dealing properly with the ? and/or the & in the url that I am searching in the script.The search is looking at a table with from 1 to 50 entries in it (there are many empty entries), depending on officer selected at a high level. The display allows for you to select a closer view (like google maps and the like although a much simpler display, only text boxes) which has more details about a given officer. It is set up like an upside down tree, officer name/number, next level has district information related to officer, further down has personal specialties/accomplishments. Most options are separate links. I am trying to write a script to help traverse this set up and copy information to a database. I keeping getting a variable is empty a few lines down, but I am sure the issue is in this line. I cannot find details about how to deal with these expressions in a url when parsing it.

Link to comment
Share on other sites

How much of it do you really need to grab? Is "http://xxxxxxxx.com/officer.aspx?cmp=1&" guaranteed to be in every URL you're parsing? If so, ignore it.Now, if all you REALLY want is the number, let's capture it. That might leave you with something like this:s="http://xxxxxxxx.com/officer.aspx?cmp=1&ofn=G64665";m=s.match(/ofn=([A-Z][0-9]{5})/);alert (m[1]);For that matter, you could play with the string.split() method, using "=" as your delimiter.

Link to comment
Share on other sites

Hey, thanks.

s="http://xxxxxxxx.com/officer.aspx?cmp=1&ofn=G64665";m=s.match(/ofn=([A-Z][0-9]{5})/);alert (m[1]);

The ofn=GXXXXX changes with each entry, so my match would have to be to everything before that, while still capturing the ofn= number. Wouldn't your code only match links to the ofn=G64665? The url before that ofn=# would be static for all entries.FYIThe first level will always have that set up.The next level does as well (the officer.aspx changes to whatever detail is called ie location.aspx, title.aspx). After that, the url changes (the detail and the cmp=1, but there is no pattern that I can figure out between the detail and the cmp) for each link. I am not sure what the cmp=1 (or =2,=3,etc) is doing. I am grabing the links and opening them via greasemonkey, parsing info and sending it to a Mysql database by way of a php script.The code, the database and the domain control from the existing site is not available for viewing (long story short, the owner listed on the webhosting agreement is no longer involved in the organization and has moved without giving over the control of the website domain) It is being worked on, but some business needs to be done with the existing information, that cannot wait. So I am trying to set up a page ripper to grab most of the needed information. I have been playing with this, but its still mucked up somewhere. I had a script that worked previously for something very similar, and I was using it to do this. After looking it over, I think I need to do this from scratch. I have too many sections with un-needed code and it has already been hacked to work previously. I think I need a clean script, and will redo this. I will revisit this if it continues to be a mess. Thanks again for the help.Isn't volunteer work lovely?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...