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 9180525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:04:42+00:00 2026-06-17T18:04:42+00:00

I am trying to pass HTML using QueryPath . I would like to get

  • 0

I am trying to pass HTML using QueryPath. I would like to get the value of a Javascript variable in the HTML. Like this:

<script type="text/javascript">

        var base_url = "http://www.exampleurl.com/";
        var room_id = "357"; //I want to get the value of room_id
        var selected_room_button = "";

</script>

I want to get value of Javascript variable *room_id* which is 357
How can I achieve this?

Even if not using QueryPath, are there any other HTML parsers that can enable me to do this kind of parsing?

  • 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-06-17T18:04:43+00:00Added an answer on June 17, 2026 at 6:04 pm

    You can use a regular expression. This code will return the room id in your example.

    <?php
    
    $html = '
    <script type="text/javascript">
        var base_url = "http://www.exampleurl.com/";
        var room_id = "357"; //I want to get the value of room_id
        var selected_room_button = ""; 
    </script>';
    
    $pattern = '/var room_id = "(.*)";/';
    preg_match($pattern, $html, $matches);
    $room_id = $matches[1];
    

    But there is no general solution as a variable may have been defined twice, or have been defined in different scopes.

    If you don’t need to extract other content beside the row_id I would see no reason for using a HTML parser. It would just slow down things. Also please expect the HTML parser not being a Javascript parser! The HTML parser would just being used to extract the unparsed content between <script> </script> tags – as a string. You would need a regex again to extract the row_id.

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

Sidebar

Related Questions

I am trying to pass a variable to a Selenium PHPUnit script using the
I`m trying to pass the Html.Textbox value in the javascript url but it is
I am trying to pass a variable to a php script using XMLHttpRequest and
I'm using Html.BeginForm and trying to pass the supplied value of the textBox archName
I'm trying to pass a JavaScript variable to the server-side using jquery.ajax method. I'm
I'm trying to pass a link_to block with html but can't get it. I
I am trying pass class as value in hashmap. I need to get the
New to MVC, trying to pass a variable from Flash using FSCommand (works well
I am trying to send some html data to php script using ajax xmlhttprequest
I'm trying to pass a variable from one page to another using google app

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.