Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using JS to extract info from HTML web page client side

Status
Not open for further replies.

mmerlinn

Programmer
May 20, 2005
748
US
[ ]

I need to extract info from a web page using my javascript already embedded in the same web page. Is that possible?

1) I have no access to the server, so JS must work client side
2) JS must be encoded in HTML web page BEFORE page is sent to server for dynamic processing
3) Web page returned from the server is different than the one sent, but will contain my code and links unchanged
4) No external JS is allowed in pages going to server (no includes)
5) JS activated when user clicks a link on returned web page
6) JS searches returned page for specific different info, then sends this info to new page according to the link clicked
7) To avoid errors, all of this must be transparent to the user

I know how to send static info to a new page via the URL.

I don't know how to use the embedded JS to search the same page for specific dynamic info.

I don't know if this is even possible.

And I have not found anything in Tek-Tips or elsewhere on the web that helps me.

Any thoughts on this?


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
[ ]
Right now for eBay listings.

However, I see other uses in the future if this is possible.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
So you are trying to inject your own javascript into a page generated from another server and have that code execute and return info to you?

This used to be possible depending on the nature of the page you are submitting information to and how it is processed server-side but it was very limited depending on the individual submission and response pages. It was also a major security hole and so has been corrected on most major systems. There is generally no good reason for something like this to be used.

If I misunderstood your question let me know but it really sounds like you want to inject your code into a form page in a way that the server response page would end up executing the code upon it's display. There are few if any legitimate reasons to do this but there are many ways this could be exploited to ill-purpose so you should actually hope that it cannot be done just for safetys sake.


At my age I still learn something new every day, but I forget two others.
 
[ ]
theniteowl

You have misunderstood. I do NOT want the code to execute server side at all. Nor do I want it to automatically execute on return.

I want JS to be executed client side when and ONLY when the user clicks on my link on the returned page. But this cannot be accomplished unless I insert the JS into the page BEFORE the server side processes the page. Once the page is returned it cannot be altered in any way by me or anyone else.

I want the user to click on a link on the returned page. When the user clicks the link I want to have the JS on the returned page extract info from the returned page and send that info to a different page on a different server. Once there, the new server will generate a page dependent on the info extracted from the returned page from the original server.

For example:

1) I generate HTML page containing JS
2) I post page on eBay
3) User agrees to buy item
4) eBay processes page on their server
5) eBay returns page will all of my code unchanged and not executed
6) User clicks checkout link
7) JS extracts final price from returned eBay page
8) JS sends final price to checkout page via URL
9) Checkout page is generated containing the correct final price (Checkout page is on my server)
10) User finalizes sale

Does this clear anything up, or did I just muddle the waters more??


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
[ ]
shaned

I don't understand. Could you elaborate a bit?

Thanks.




mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Is it a normal feature for eBay to allow your javascript code passed through it's server and returned to the client?
If yes then it should be easy but if not then it still sounds as if code injection is being attempted which is probably not going to work for you.

In any event, using Javascript to obtain and send the values for you is not a safe method for you, let alone the client. Client side code can be easily tampered with allowing the person the ability to mess with the values passed to you from the eBay page javascript. You would need some significant code on your server to re-validate the information.

If eBay just displays the page you have created then your page just has to post itself to your own server page script and read in the form values, whether the Javascript comes into play or not.

I have not worked with eBay pages. If there are restrictions in the way it operates then please describe them and we will have a better idea of what the problem is you are trying to address. What specific obstacles are you dealing with or is it just that you do not know how to go about submitting the page to your server page?

At my age I still learn something new every day, but I forget two others.
 
from the greasemonkey site []

Greasemonkey is a Firefox extension which lets you to add bits of DHTML ("user scripts") to any web page to change its behavior. In much the same way that user CSS lets you take control of a web page's style, user scripts let you easily control any aspect of a web page's design or interaction.

For example, you could:

* Make sure that all URLs displayed in the browser are clickable links
* Improve the usability of a site you frequent
* Route around common and annoying website bugs
* Use the Coral content network selectively.

There are lot's of scripts around, including some that work on the ebay site.

Shane
 
[ ]
theniteowl

eBay restrictions

Any JS or HTML code that the seller puts in the member content area of an eBay page is returned from the eBay server unchanged. eBay does not allow code outside of the member content area. Furthermore, eBay does not allow any code which can be executed on their server. To filter out 'illegal' code, eBay checks the page BEFORE they accept it as an auction listing. Once accepted, the seller page is incorporated into the larger listing page.

When eBay processes the page upon completion of the auction, they ONLY change the parts of the page that are NOT part of the seller submitted page, and they just pass the seller submitted part through their system unchanged.

Here are the limitations on code that can be used:

[tt]Not permitted

* HTML or JavaScript used to drop or read a cookie on any eBay page
* HTML or JavaScript that redirects the user from eBay to another page (such as the "replace" script)
* HTML or JavaScript that automatically calls remote scripts and pages (such as JavaScript includes or iframes)
* HTML or JavaScript that changes registry entries, or otherwise writes to another's computer hard drive
* HTML or JavaScript that creates automatic "pop-ups" (exception - links that open in a new window when clicked on)
* HTML or JavaScript that automatically posts to scripts in eBay
* HTML or JavaScript that automatically loads any binary program on another's computer exception - Flash content)
* HTML or JavaScript that automatically overwrites any area on the listing outside of the item description area
* Manipulation of areas outside the listing description, including changing fonts, colors, backgrounds, etc. in areas such as eBay headers, footers, etc.
[/tt]

And here is what happens if illegal code is used:

[tt]Attempts to use the disabled scripts will return a very specific error message that begins: "Disallowed JavaScript/HTML Syntax". Members will be prevented from listing the item or will be disabled at run-time. Any other JavaScript error indicates a separate issue and is not related to the disabling of these scripts.[/tt]

Basically anything that has the potential to harm eBay or eBay members is not allowed.


Client side code

Tampering with client side code in this case is not likely to be an issue at all.

The vast majority of buyers would not have the foggiest idea that it could be done, much less do it. Those few that have the knowledge to do it simply wouldn't be likely to be bothered for ten, twenty, thirty, or even hundred dollar items. And even if someone tried it, the systems in place would flag the sale as suspect. Then the submitted payment could be checked against the eBay-archived eBay page for correctness before the items were actually sent to the buyer.

Currently, the buyer MANUALLY fills in the information himself at the conclusion of the listing. In eight years we have never seen the buyer fill in the incorrect information. Based on this, we do not see client side code being an issue here. All I am trying to do is automate what the buyer is already doing manually.


Current practice - UNKNOWN ending price

For an example of current practice for auction listings that have an UNKNOWN ending price at listing time:

1) Go to this link:


2) Click on any auction listing
3) Scroll down to the big green box near the center of the page
4) Click on the "Click here for order form" link
5) Look at the line "__________ Ending price for item code: "

The buyer currently manually fills in the blank with the ending auction price. I want to fill this blank in automatically with the correct ending price when the buyer clicks the order form link. This information is available on the ended-listing page that this link is on. All I need to do is find a way to search the ended-listing page for the ending price, then send that ending price to the ordering link page.


Current practice - KNOWN ending price

For an example of current practice for BUY-IT-NOW listings that have an KNOWN ending price at listing time:

1) Go to this link:


2) Click on any buy-it-now listing
3) Scroll down to the big green box near the center of the page
4) Click on the "Click here for order form" link
5) Look at the line " $ xx.xx Ending price for item code: "

When the ending price is KNOWN BEFORE the listing ends the ending price is hard coded into the ordering link. When the buyer clicks the link, this price is automatically inserted into the order page.


Conclusion

My knowledge of anything server-side is less than zero. So if the only way to accomplish what I want to do is to go server-side, I am not sure that the time spent learning server-side programming is worth the effort for this relatively trivial task.

My knowledge of JS and HTML also is woefully lacking, but so far I have been able to muddle through to get the job done.

My programming expertise lies in FoxPro and some older languages. All of the HTML and JS code within the listing description area of the eBay pages at the above links was generated from a database using a FoxPro program I wrote and have been continually improving for years. If there is a way of doing what I want to do client side, I will add that to the FoxPro program for all future generations of eBay pages. Otherwise, I will probably leave things as is and continue to let the buyer manaully fill in the blank.


mmerlinn

"Political correctness is the BADGE of a COWARD!"
 
[ ]
shaned

Thanks. I took a quick look at some of the source code for some of the scripts. It looks like what I want to do is possible, but it is going to take me a long time trying to figure out how those scripts work so I can modify them for my needs.

My knowledge of JS is very limited and most of the source code I looked at is way over my head. I simply have no idea how most of it works.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
What is it that you need to do on the page once the client clicks your link or button? You said search for specific information but are you talking about info in named fields?
Are you talking about text displayed on the page?

You need a predictable method of recognizing the data you want to find. The method you use for retrieving that info depends on the nature of the info and what means you have of identifying it. You could use Javascript to parse out the entire textual content of the page but unless you can tell the script what to look for you have no chance of finding it.
If what you are looking for is content in form fields you just have to know the name/id of those form fields and possibly the form name. If it is your own form showing up then it should be easy.


At my age I still learn something new every day, but I forget two others.
 
[ ]
theniteowl

I need to search for text visible on the page. Then pass that info via the URL to the new page.

The source code for the text is always in this format where the item I want to pass to the new page is in red:

[tt]<span id="DetailsCurrentBidText" class="titlePurchase">Winning bid:</span></td><td nowrap><span id="DetailsCurrentBidValue"><b>US $27.99 </b></span>[/tt]

In case you need further info about the page I took the above source code from, please examine the source code for the page at this link:



mmerlinn

"Political correctness is the BADGE of a COWARD!"
 
Since the text you need occurs within a span with a given ID you could use something like:
var myvalue = document.getElementById('DetailsCurrentBidValue').innerText;
This would retrieve the value for you, then you can append that value to your querystring to call the next page with.

Your button or link on the page that triggers the send would just call the function to extract the value, build the new URL and then change the page location.

At my age I still learn something new every day, but I forget two others.
 
Ok.

Will do some playing around with that and see what I can make happen.

Won't have time to try this for a few days, so will get back to you sometime next week with my solution or more questions.

Thanks,



mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
theniteowl

I have played around with this for weeks, and I still can't get it to work. I have tried it on multiple versions of NS and FF, but I always get the error 'undefined'. I haven't tried it on IE, but I assume that it wouldn't work there either if it won't work on NS or FF.

I have also examined all of the books I have on JS, and not a single one of them even has the word 'getElementById' or 'innerText' in them.

Here is the code I used for the latest test:

[blue]

<html>

<h2 id='george'>999</h2>

<body>
<script language ='javascript'>

var myvar = document.getElementById('george').innerText
document.write(myvar)

</script>
</body>
</html>
[/blue]


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top