Jump to content

return element by id


TheHamburgler

Recommended Posts

Hi,How would i go about searching a webpage for a defined tag/word and the text after it?I have looked into a number of methods like getElementById and getElementsByName but they dont do what i need.I need to point the script to a page on the web, eg www.thispage.com/thisone.html Then I want to search the html for all instances of the word product_id="xxxx" and then return each product id (5 digit code) as a seperate string of numbers.Thanks :)

Link to comment
Share on other sites

Unless your script will be running on the same domain as the files that you are trying to get, I believe you'll have to use server-side code to accomplish this. Check out PHP or ASP.NET. With those, you can create an HTTP Request on the server that sends out a request to the other website to get a particular file and store the response text in a string variable (or in an XML object if it's XHTML). Then, using regular expressions (or, if it is an XML object, you can use an XML parser), you can get at the information you want.

Link to comment
Share on other sites

Yeah I know, I'm looking for that string within the html file. It's not part of the html code but will be enclose in the <a></a> tags on the page.It's for a dashboard widget I'm trying to develop that will look to a DVD rental website and tell me what DVDs I have on rent or being delivered.Here's a snippet of the html<a href="/product/detail.html?product_id=xxxx" title="West Wing, The - Complete Season 1 - Disc 4">West Wing, The - Complete Season 1... Disc 4</a>Once I'm able to return the product_id=xxxx I can find the get the url of the DVD image to present in the widget.It's getting a bit tricky though so it will probably hit the rubbish bin in a few more weeks :)

Link to comment
Share on other sites

Yeah I know, I'm looking for that string within the html file. It's not part of the html code but will be enclose in the <a></a> tags on the page.It's for a dashboard widget I'm trying to develop that will look to a DVD rental website and tell me what DVDs I have on rent or being delivered.Here's a snippet of the html<a href="/product/detail.html?product_id=xxxx" title="West Wing, The - Complete Season 1 - Disc 4">West Wing, The - Complete Season 1... Disc 4</a>Once I'm able to return the product_id=xxxx I can find the get the url of the DVD image to present in the widget.It's getting a bit tricky though so it will probably hit the rubbish bin in a few more weeks :)
Well, is that page on your server? Can you access it with AJAX? If so, it would be simple to fetch it with ajax, put the content of the body tag into a hidden div, loop through the links in that div, check if the hrefs of any of them contain product_id, then split it out and return it in an array. :)
Link to comment
Share on other sites

Well, is that page on your server? Can you access it with AJAX? If so, it would be simple to fetch it with ajax, put the content of the body tag into a hidden div, loop through the links in that div, check if the hrefs of any of them contain product_id, then split it out and return it in an array. :)
Thanks for you're help, that's what i'm trying to do. I do not have access to the server, its a 3rd party site, can I still return the html file to a variable? The page is public and only depends on the user having a cookie to remember their account details.
Link to comment
Share on other sites

Thanks for you're help, that's what i'm trying to do. I do not have access to the server, its a 3rd party site, can I still return the html file to a variable? The page is public and only depends on the user having a cookie to remember their account details.
Well, you can use AJAX and a PHP screen scrape file on your server.Try reading this topic, starting with this post:http://w3schools.invisionzone.com/index.ph...ost&p=19658It'll help you with screen scrapes. :)
Link to comment
Share on other sites

Well, you can use AJAX and a PHP screen scrape file on your server.Try reading this topic, starting with this post:http://w3schools.invisionzone.com/index.ph...ost&p=19658It'll help you with screen scrapes. :)
Cool, I took a look.One problem though, it's for an Apple Widget which will just run on a users dashboard. Is there away way to achieve it without needing access to a php server?Currently I dont have one set up, I was hoping to achieve this through a standalone script run from the browser :)Each person who uses it will be directed to the same url http://www.lovefilm.com/account/selection.html but each will have different product_id's on their page.Even if i were to scrape the page to a php server each request would be different depending on the person using the widget...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...