Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:35+00:00 2026-05-27T23:50:35+00:00

I had a webscraping technique all worked out in PHP until I found out

  • 0

I had a webscraping technique all worked out in PHP until I found out that the platform I was developing it on (iOS via phone gap) didn’t support PHP. I found a solution though, via JS.

$(document).ready(function(){
  var container = $('#target');
  $('.ajaxtrigger').click(function(){
    doAjax($(this).attr('href'));
    return false;
  });
  function doAjax(url){
    if(url.match('^http')){
      $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
                "q=select%20*%20from%20html%20where%20url%3D%22"+
                encodeURIComponent(url)+
                "%22&format=xml'&callback=?",
        function(data){
          if(data.results[0]){
            var data = filterData(data.results[0]);
            container.html(data);
          } else {
            var errormsg = '<p>Error: could not load the page.</p>';
            container.html(errormsg);
          }
        }
      );
    } else {
      $('#target').load(url);
    }
  }
  function filterData(data){
    data = data.replace(/<?\/body[^>]*>/g,'');
    data = data.replace(/[\r|\n]+/g,'');
    data = data.replace(/<--[\S\s]*?-->/g,'');
    data = data.replace(/<noscript[^>]*>[\S\s]*?<\/noscript>/g,'');
    data = data.replace(/<script[^>]*>[\S\s]*?<\/script>/g,'');
    data = data.replace(/<script.*\/>/,'');
    return data;
  }
});

The way the URL is loaded is by clicking a link and it get’s the href of it and populates url (at least I think). I want the url to be static though, such as http://website.com and being pre populated. I tried replacing all doAjax(url) with doAjax('http://website.com) but that doesn’t seem to work and I would like to know what I’m doing wrong.

Another problem with the new JS script is that I want to be able to parse the results and only show the table element. In PHP, I did this using:

data =  $html->find('table');
echo $data[1];

What would the equivalent be in javascript of that PHP function?

On a side note, I was considering splitting this up into two posts, but I thought that would be too many posts for tonight 🙂

Edit: First problem was solved by @nnnnnn in the comments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:50:35+00:00Added an answer on May 27, 2026 at 11:50 pm

    If you’re saying the above code works when the links are clicked (via the click handler calling your doAjax() function), but you also want to automatically call it for 'http://website.com' without having to click, just add doAjax('http://website.com'); to the end of your document.ready function.

    As far as extracting just a particular table from the response, within your ajax callback function you can create a jQuery object from the returned data, and then use jQuery’s .find() method to extract the part you care about, and .append() to add that part to your container element:

      function(data){
        if(data.results[0]){
          var fullResponse = $(filterData(data.results[0])),
              justTable = fullResponse.find("table");
          container.append(justTable);
        } else {
          var errormsg = '<p>Error: could not load the page.</p>';
          container.html(errormsg);
        }
      }
    

    Note that the selector for .find() may need more information to select specifically the table you are talking about. Not sure if "table:first" would do it, or if that table has an id attribute you could use instead: .find("#thetableidhere"), or…?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had to delete all the rows from a log table that contained about
Had no luck getting this to work via what I found on google.
Had to deploy some PHP code onto a shared server with only PHP5.2.8. All
Had a question about a implementation of bind function that I found on Mozilla's
Had finally gotten all the bugs out of this and now they said Oh,
Had to deploy some PHP code onto a shared server with only PHP5.2.8. All
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
I had a discussion with some colleagues mentioning that there are not too many
I had the idea of a search engine that would index web items like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.