Price selector from online store - xpath

I want to extract the price of certain product from banggood (i.e. http://www.banggood.com/Wholesale-IMAX-B6-Digital-RC-Lipo-NiMH-battery-Balance-Charger-p-46220.html) using google spreadsheets.
Right now I can grab the price but also other values using this string:
=IMPORTXML(A6 ; "//*[contains(#class, 'now')]")
I get this:
21.68
Buy it now
I just want to get the actual value that is within this:
<div class="now" oriprice="21.68">363.69</div>
it should be the "353.69" alone, (that's the price in mi currency , MX).
I also tried this:
=IMPORTXML(A6 ; "//*[contains(#class, 'now')] and string('oriprice')")
but returns TRUE not the value
Any help would be appreciated.

21.68 is actually a correct result.
When you do scraping you should always consider real server response, but not what you see on scree.
So go to source and see real HTML. See picture below (that is the page u mentioned)
and reason why u get Buy Now is
So write this
=IMPORTXML(A6 ; "//*[#class = 'now']")

The reason you get 21.68 is because that's the price in US dollars, which appears to be the site's base currency.
When you View Source, as Dmytro suggests, you might see a different value in the div containing the price. I see 14.26, for example, because that's the price in my currency.
This value is being updated after the page has been loaded. That page's Javascript is detecting your country, setting a cookie with your currency in it, and then making an AJAX call to this page:
http://www.banggood.com/index.php?com=product&t=initViewHistory&utm_medium=&product_id=46220
That is returning an HTML snippet with the price in your own currency, which the main page's Javascript is then inserting into the page.
Your problem, as far as the spreadsheet goes, is that when you use Google Sheets to fetch that page (a) Google Sheets won't run the Javascript and (b) Google's request to the store's site will probably be detected as being in the US and so even if the JS were run it wouldn't actually change the price.

Related

custom routing in magento

I have multi store views in website,
The current URL for a category for the dutch store view would be;
http://www.domain.ext/nl/category.html,
http://www.domain.ext/de/category.html etc
Now I want to add country code with store code. I mean to say, I am getting country code from Users Ip and want to extend it with store code. It will be look like
If the country is set to NL the URL should now be;
http://www.domain.ext/nl_nl/category.html
If the storeview is Dutch (NL) but the country is Belgium (BE), the URL should become;
http://www.domain.ext/nl_bel/category.html
I want this only in category page. I am trying to change in match function of standard.php, but I think its role starts from controller name, please help me how can I achieve it. Any help is highly appreciated.
Are you sure you want to incorporate it into the URL like that?
I think you are going to fight a lot of Magento code to achieve it (product url, catalog url, indexing, getUrl functions and collections, rewrites).
I'm sure you have considered this and the many ways to do what you want but I think you are making work for yourself. Perhaps adding the country code as a URL query string ?c=bel or keeping it all internal to Magento by storing it in a session variable or a general function that you can call at any time eg getCustomCountryCode(). Using a cookie might be a possibility too.
If the URL is purely cosmetic then perhaps an .htaccess rewrite would suffice combined with some rel='canonical' href="http://www.domain.ext/nl_bel/category.html" on the category pages.
If you are determined to proceed then study the class Mage_Catalog_Model_Url

Mturk External Survey Code

I am trying to link up Mturk to my external Website
I am using the external survey Hit on the GUI requester page
I know that I need to generate the code myself, but I do not know how the code is validated.
In what form or fashion do I, or the Amazon site validate this code? and how do I implement this.
For example: A person gets a code from my website, and pastes it into the box of their amazon hit on the amazon website. Who is that code validated by? and if amazon how to I tell them which codes have been generated?
Thanks in advance!
You would do it yourself. you will find the code that the worker enters on the HIT page in your results file. Than you compare the results file with the list of codes you generated, and approve the correct codes.
A method is described on my blog which is ideal for surveys with lots of participants. Basically, you export the data from both your survey and Mechanical Turk, then you put the code columns side-by-side for comparison, and then you use a formula that takes each row of one column of codes and performs a lookup in the other column of codes. For example, you could use a COUNTIF formula in Excel, which returns a 1 if there is a single match, and a 0 otherwise.

Is it possible to show the order details sent to customer via email in a separate page (Magento)?

Is it possible to show the order details of last processed order, such as
Item Sku Qty Subtotal
in a separate page?
I tried adding the order details section from frontend/base/default/template/email/order/items/order/default.phtml in a separate cms page, by adding {{layout handle="sales_email_order_items" order=$order}} to it.
But, when I run this cms page after order being placed, it shows the following error:
Fatal error: Call to a member function getAllItems() on a non-object in D:\wamp\www\magento\app\design\frontend\base\default\template\email\order\items.phtml
Is this actually possible?
This is possible.. its already present in the magento system, when user places an order successfully they are shown with order number and a link to order details page.
the link to order page is like http://www.example.com/sales/order/view/order_id/25/
we can make system to be redirected directly to this page to accomplish this task.
the only this we needed is the order id this can be get using
Mage::getSingleton("checkout/session")->getLastOrderId();
Yes, most things are possible. You'd have to write your own module, with your own controller which would serve up your own template. There you can load up an order and display whatever you want.
Obviously, that isn't the answer you are hoping for, but your question isn't specific, and writing out how to accomplish what you want could easily take an entire blog article.

How add custom field in cart and sent in the order

I have one question about shopping. I need aggregate one field Giftwrapped your order? Yes No. name=giftwrap id=giftwrap value=functionevalue(Radio) this validation is javascript and function, no problem with this. Now i have take the value giftwrap and send to group ajax and show this value in checkout review before confirm order, and then send the comment: the gift should be wrapped in the orden in the backend. I try, i search but no nothing functioned, please help.
Take a look at this Order Attributes extensions. It does exactly what you want for a relative cheap cost.

Automating filling Forms

Renting houses can be nasty so I need to automate it. Please, have a look at here. If you make a mistake, all of your changes are gone. I tried to insert the values in the url like:
https://www.hoas.fi/web/hak_inet.nsf/WebHakemus?OpenForm&02.07?PersonFirstName=Alex?PersonLastName=Smith
but it does not work. What is the problem?
Firstly, your query string is incorrect. It should be:
https://www.hoas.fi/web/hak_inet.nsf/WebHakemus?OpenForm&02.07&PersonFirstName=Alex&PersonLastName=Smith
Secondly, in order to pre-populate the page with the results of the query string, the developer of the page would have had to added logic to extract the query string values and pre-populate the page with those values. In this case, it does not appear that they have done that.
You could try saving the page locally as HTML. Then you could modify the HTML to include your default values. You would also need to update any relative paths to point to the server as a full URL. Then you could open the page on your machine and hopefully post to the server. This assumes that they are not injecting any session or other temporary information in the page that they validate.

Resources