Friday, 28 June 2019

How do i scrape AngulaJS site data with conditional decision tree for each final answer?

Given an example URL endpoint like this, how would you go about scraping the final price for each combination of conditions and output it to excel in PHP?

I found the json data in the HTML and decoded it, but mixing each condition and following it through to arrive to each final total price is seeming a problem. I thought of using switch statements, but with the use of the go_to logic, they managed to implement copies of the same data hence risk repeating myself.

Here is how i had started out with my switch statements

<?php
  $json = '';


  $json_d = json_decode($json, true);
  foreach($json_d as $s => $set){
    foreach($set['questions'] as $q => $question){
      process_question($question);

    }
  }

  function process_question($question){
    switch ($question['text']) {
      case 'What is the condition of the phone?':
        process_condition();
        break;

      default:
        # code...
        break;
    }
    // foreach($question['answers'] as $a => $answer){
    //   // print_r($answer);
    // }
  }

?>

Lump of json for that specific endpoint is here. Wanted to keep the post short.

If you browse through the decision tree leading to each final total sum, you will know what i mean to implement and out put to excel.



from How do i scrape AngulaJS site data with conditional decision tree for each final answer?

No comments:

Post a Comment