Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22278 > unrolled thread

JavaScript get specific values from web page and add them to end of url in a multiple tabs

Started bychozze@gmail.com
First post2013-12-10 09:40 -0800
Last post2013-12-15 21:44 -0800
Articles 12 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  JavaScript get specific values from web page and add them to end of url in a multiple tabs chozze@gmail.com - 2013-12-10 09:40 -0800
    Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs JJ <duh@nah.meh> - 2013-12-11 11:28 +0700
      Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-13 01:31 -0800
        Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-13 01:38 -0800
          Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-13 12:26 +0000
            Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-13 08:39 -0800
              Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-13 17:37 +0000
                Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-14 02:00 -0800
                  Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-14 02:16 -0800
                    Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-14 03:03 -0800
                      Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-12-14 12:18 +0000
                        Re: JavaScript get specific values from web page and add them to end of url in a multiple tabs Izmarias Klon <chozze@gmail.com> - 2013-12-15 21:44 -0800

#22278 — JavaScript get specific values from web page and add them to end of url in a multiple tabs

Fromchozze@gmail.com
Date2013-12-10 09:40 -0800
SubjectJavaScript get specific values from web page and add them to end of url in a multiple tabs
Message-ID<4ef66f86-2f6a-402f-875d-e8d21cae20c6@googlegroups.com>
I want to use tampermonkey with Chrome to do this I am inspired by this code http://hibbard.eu/tampermonkey-tutorial/

1) First I need to collect the values to array 
ID: 70966, Obratnik raka (slovensky)  ...  65,- Kc 
ID: 88853, Mechanickz pomeranc  ...  65,- Kč 

From this sample code I need just numbers after ID:

2) then open in multiple tabs for each item and at the end of the url should be ID number (after id=)

http://antikvariat-smichov.cz/detail.php?kategorie=28&id=90021

I examine the example witch I mentioned above but there he simply specify by jquery to extract urls based on css style I cant not do that in this example. Also when he gets the array it is already full url wich he can easily refer to

ok checked the similiar questions but no better idea

I think I put numbers into array by this

$(document).ready(function() {
var hrefs = new Array();
var elements = $('.headline > a');
elements.each(function() { 
hrefs.push($(this).attr('href'))
});

any ideas how to solve this or first maybe find the right command for getting that numbers?

any help appreciated, thank you

chozze

[toc] | [next] | [standalone]


#22284

FromJJ <duh@nah.meh>
Date2013-12-11 11:28 +0700
Message-ID<s35nuogal3hq.325eherpxdub$.dlg@40tude.net>
In reply to#22278
On Tue, 10 Dec 2013 09:40:45 -0800 (PST), chozze@gmail.com wrote:
> any ideas how to solve this or first maybe find the right command for getting that numbers?

If you're going to use the ID number on a different URL, you'll have to
parse the source URL to retrieve the ID number then append/insert it into te
target URL.

Once you have the full URL, open it in a new tab with this:

  window.open(url, "_blank");

If the URL is already the one you want to open, then there's no need to
parse it. Simply open it in a new tab.

[toc] | [prev] | [next] | [standalone]


#22294

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-13 01:31 -0800
Message-ID<e9a92946-0883-41b1-b774-7702ae9b89e1@googlegroups.com>
In reply to#22284
thank you you really make this much more simplier for me I still was trying how to get that number from html code, parse url seems much easier now I am looking for right command

[toc] | [prev] | [next] | [standalone]


#22295

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-13 01:38 -0800
Message-ID<fa1f0519-7dc9-42ee-84eb-c76980fc3f21@googlegroups.com>
In reply to#22294
no that will not work original url is

http://antikvariat-smichov.cz/admin/admin.php?akce=maily&mailik=25816

and at the end is the id of the mail I need a ID of a book wich is in html so I need to extact that number from webpage still

[toc] | [prev] | [next] | [standalone]


#22296

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-12-13 12:26 +0000
Message-ID<0.7f8984a56cfb4e84b818.20131213122634GMT.87bo0l543p.fsf@bsb.me.uk>
In reply to#22295
Izmarias Klon <chozze@gmail.com> writes:

> no that will not work original url is
>
> http://antikvariat-smichov.cz/admin/admin.php?akce=maily&mailik=25816
>
> and at the end is the id of the mail I need a ID of a book wich is in
> html so I need to extact that number from webpage still

It would help if you gave an example of the HTML from which you want
extract the book ID.  Some punctuation would help too.

There is also a question in my mind about what you mean by "in multiple
tabs", but it may be better to deal with one thing at a time.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#22299

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-13 08:39 -0800
Message-ID<3a6a608d-68e9-42ce-bf08-5452df369265@googlegroups.com>
In reply to#22296
hi thx for reply the code is like this

<b>Objednávka</b><br><br><b>Položky: </b><br />ID: 71376, Hygiena mléka&nbsp;&nbsp;...&nbsp;&nbsp;85,- Kč<br />ID: 56720, Mechanisace v mlékárenském průmyslu&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 42002, Tukové mlékárenské tabulky&nbsp;&nbsp;...&nbsp;&nbsp;125,- Kč<br />ID: 56734, Základy hospodárnosti mlékárenského prům.&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 58326, Balení mléka systémem polipack&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 55324, Sýry na vašem stole&nbsp;&nbsp;...&nbsp;&nbsp;125,- Kč<br/><br />

the problem is that I need the numbers (IDs) than each open in new tab wich address should look like this

http://antikvariat-smichov.cz/fotka.php?id=71376 (for first ID)
http://antikvariat-smichov.cz/fotka.php?id=42002 (for second ID)

as I find out is pretty simple to extract whole text that is between tags but specific text within the tags?

this is the closiest example I found and it says its tricky

http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/

[toc] | [prev] | [next] | [standalone]


#22301

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-12-13 17:37 +0000
Message-ID<0.0c5571532329e3f72a42.20131213173748GMT.87d2l04poz.fsf@bsb.me.uk>
In reply to#22299
Izmarias Klon <chozze@gmail.com> writes:

> hi thx for reply the code is like this
>
> <b>Objednávka</b><br><br><b>Položky: </b><br />ID: 71376, Hygiena mléka&nbsp;&nbsp;...&nbsp;&nbsp;85,- Kč<br />ID: 56720, Mechanisace v mlékárenském průmyslu&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 42002, Tukové mlékárenské tabulky&nbsp;&nbsp;...&nbsp;&nbsp;125,- Kč<br />ID: 56734, Základy hospodárnosti mlékárenského prům.&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 58326, Balení mléka systémem polipack&nbsp;&nbsp;...&nbsp;&nbsp;65,- Kč<br />ID: 55324, Sýry na vašem stole&nbsp;&nbsp;...&nbsp;&nbsp;125,- Kč<br/><br />
>
> the problem is that I need the numbers (IDs) than each open in new tab
> wich address should look like this
>
> http://antikvariat-smichov.cz/fotka.php?id=71376 (for first ID)
> http://antikvariat-smichov.cz/fotka.php?id=42002 (for second ID)
>
> as I find out is pretty simple to extract whole text that is between
> tags but specific text within the tags?
>
> this is the closiest example I found and it says its tricky
>
> http://james.padolsey.com/javascript/replacing-text-in-the-dom-its-not-that-simple/

This seems to be a PHP-based site, so if it is at all possible you
should solve the problem on the server side, generating the links rather
than plain text IDs.

If that's not possible, then you seem to have found a page that
describes a solution, so why not use it?  There may be things about it
you don't like, but without you saying what they are, it's hard to know
what to suggest.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#22306

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-14 02:00 -0800
Message-ID<25a721b5-abd8-4b27-9a14-a7d92c999d0e@googlegroups.com>
In reply to#22301
yeah I am new to js and pick up a diffucult problem as I see after yesterday allday reserach. so I find out how to search and use redex

this is example from example page

jQuery('p').each(function(){
 
    var p = $(this);
 
    p.html(
        p.text().replace(
            /\bRF\d{5}/g,
            '<a href="/order/$&">$&</a>'
        )
    )
 
});

in my case it would be

jQuery('p').each(function(){
 
    var p = $(this);
 
    p.html(
        p.text().replace(
            /\d{5}, // any 5 digit number
            '<a href="/order/$&">$&</a>'
        )
    )
 
});

what I want to solve today is check if this works and than put results in array

[toc] | [prev] | [next] | [standalone]


#22307

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-14 02:16 -0800
Message-ID<cc0a9a83-cb0e-4f34-bc30-2c7ac2f04bb7@googlegroups.com>
In reply to#22306
no it should be like this

jQuery('table').each(function(){ 
  
    var p = $(this); 
  
    p.html( 
        p.text().replace( 
            /\d{5}, // any 5 digit number 
            '<a href="/order/$&">$&</a>' 
        ) 
    ) 
  
}); 

[toc] | [prev] | [next] | [standalone]


#22308

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-14 03:03 -0800
Message-ID<36b45920-3d8d-46fb-8b56-dfc454c58d60@googlegroups.com>
In reply to#22307
getting error :-(

UPDATE

<script type="text/javascript">

jQuery('table').each(function(){

var p = $(this);

      p.html(
    p.text().replace(
        /\d{5}/,
        '<a href="/order/$&">$&</a>'

    )
   )
 }
alert(p);
</script>
but I am getting error

SyntaxError: missing ) after argument list

alert(p);

[toc] | [prev] | [next] | [standalone]


#22309

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2013-12-14 12:18 +0000
Message-ID<0.0dd87387b1cd488f4f85.20131214121833GMT.87r49fzkva.fsf@bsb.me.uk>
In reply to#22308
Izmarias Klon <chozze@gmail.com> writes:

> getting error :-(

This is not the best place to ask jQuery questions, but it happens that
your current issue is a simple syntax error.

> UPDATE
>
> <script type="text/javascript">
>
> jQuery('table').each(function(){
>
> var p = $(this);
>
>       p.html(
>     p.text().replace(
>         /\d{5}/,
>         '<a href="/order/$&">$&</a>'
>
>     )
>    )
>  }
> alert(p);
> </script>
> but I am getting error
>
> SyntaxError: missing ) after argument list

I'm worried that you can't see the problem yourself.  I think you should
learn a bit about the syntax of the language you are using, and that will
be easier if you start without a large and complex library like jQuery.
You could start by setting yourself a simper task.

There seem to be two errors in the code.  First, that '(' after each has
not matching closing ')'.  Secondly, the alert is in the wrong place.
It should be inside the function that declares the 'p' variable.

I suspect that the last two lines should really be:

  alert(p);
  });

(and putting a ';' after the preceding ')' would not hurt either.)

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#22349

FromIzmarias Klon <chozze@gmail.com>
Date2013-12-15 21:44 -0800
Message-ID<01333c00-d1e1-4f32-a95e-19117da63eee@googlegroups.com>
In reply to#22309
I thought this is going to be a simple task :-) I read smthg many times but never used it so I always forget. Bcs never found smthg in what way to use it now when I finally found it is to complex :-(

ok it works - in a sense that gives no error but cant see alert :-)

thx for answers

I do not want to give up but this is really maybe to much for begining

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web