Getting a price from a seller’s website

I am creating an iOS and Android application that scans a barcode and displays the product page of this book from the seller’s website. But now I only want to get the price from this product page not on the whole page.

How can I get the price of a product from a page, since RedLaser makes its own application with it.

Product page: http://goo.gl/rDxAg Price: 321 rubles

I need something like this , and it can be implemented on iOS and Android without using an external server.

I am new, so any help would be greatly appreciated.

+3
source share
6 answers

API - , html, . html, iOS, Android.

iOS, HTML iPhone.

Android HTML Android.

, , .

, .

+6

A jsFiddle Demo .

, , , .

Flipkart.com , .

1: http://www.flipkart.com/m/books

pid , -! pid of 9780224060875

2: http://www.flipkart.com/m/search-all?query=9780224060875

, Span Tag Class Name of sp.

<!-- Fragment of product price format -->
<div id="productpage-price">
 <p>
     Price:  <del> Rs. 350</del>
  <span class="sp">Rs. 263</span>
 </p>
</div>

, jQuery, :

// Begin section to show random methods to use HTML values

    // Get the HTML of  "Rs. 263" and store it in variable as a string.
    var priceTextAndLabel = $('#productpage-price').find('span.sp').text();

    // Get the HTML of  "Rs. 263" and slice off the first 4 characters of "Rs. " leaving "263" only.
    // Adjust the .slice() if possiable that number is after decimal point. Example: "Rs.1000"
    var priceText = $('#productpage-price').find('span.sp').text().slice(4);

    // As above but convert text string of "263" to a number (to allow JavaScript Math if req.).
    // The value 10 seen below reflects decimal base 10 (vs, octal(8) example) for .parseInt();
    var priceNumber = parseInt($('#productpage-price').find('span.sp').text().slice(4),10);

    // Firefox with Firebug Console will show BLACK characters for "Rs. 263" since it a "string".
    console.log( priceTextAndLabel );

    // Firefox with Firebug Console will show BLACK characters for "263" since it a "string".
    console.log( priceText );

    // Firefox with Firebug Console will show BLUE characters for "263" since it a "number".
    console.log( priceNumber );

// End section to show random method to use HTML values

, ... , ... URL- flipkart.com ( -).

: . , . , - iframe AJAX URL- .

, jsFiddle Demo, , AJAX.

3: jsFiddle flipkart.com


: . , API, . API API .

, API. MP3. , MP3 , , , .

+3

eCommerce, CSV , , , :

xpath: //div[3]/div[2]/div/div/div/span

Selenium Perl:

open (INFO, '>>file.csv') or die "$!";  
my $sel = Test::WWW::Selenium->new( host => "localhost", 
                                    port => 4444, 
                                    browser => "*chrome", 
                                    browser_url => "http://www.example.com/page.htm" );
$sel->open_ok("/page.htm");
$sel->click_ok("//table[2]/tbody/tr/td/a/img");
$sel->wait_for_page_to_load_ok("30000");
my $price = $sel->get_text("//div[3]/div[2]/div/div/div/span");
print INFO ("$price\n");
$sel->go_back_ok();

# Close file
close (INFO);

-

+1

URL- , , Nokogiri

, - . CSS xpath

Nokogiri:

require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML(open('http://www.YOUR_URL_HERE.com'))
price = doc.at_xpath("//span[@id='fk-mprod-our-id']").text
+1

API, . ! API , HTML XML, , . , . , , .

+1
<span class="price final-price our fksk-our" id="fk-mprod-our-id">
   Rs.
   <span class="small-font"> </span>
   315
</span>

, HTML Price tag.

I suggest you use jSoup. Download here

Now, using this library, parsing is easier, all you need to do.

 Document doc = null;

    try{
        doc = Jsoup.connect("You page URL comes here").get(); // get url contents
    }catch(IOException e){
         // Handle exception here.
    }

 String priceHtml = doc.select("#fk-mprod-our-id").get(0).html().trim(); // get specific tag
 System.out.println("html fetched: "+priceHtml); //print to check if right tag is selected
 priceHtml = priceHtml.replace("((<span(.)*?>)(.)*(</span>))", ""); // replace inner span using regex.
 System.out.println("My Price tag: "+priceHtml); 

I have not tested the code above, but it should work. It may contain a small error. but with a little effort you can make it work.

Parsingsometimes it takes time. You must do this in the background. When the background parsing is complete, send the data to the user interface stream.

Edit:

surrounds your call connectwith try catch.

and make sure you have the following permissions set to androidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
+1
source

All Articles