I want to extract data that are in table #buyOrdersTable from here
https://bittrex.com/Market/Index?MarketName=BTC-XRP
To do this I am using PHP Simple HTML DOM Parser library and following code:
$html = file_get_html('https://bittrex.com/Market/Index?MarketName=BTC-XRP');
echo 'BTC/XRP<br>';
foreach($html->find('div.buy-table-container tr.dyn-tr-add td') as $td)
{
echo $td->plaintext . '<br>';
}
?>
I want to extract every row from BID section - SUM, TOTAL, SIZE (XRP), BID (BTC). But code doesn't find any row.
You can't do that. It's impossible, as explained by msg in the comments.
To do it properly, sign up for an API key, and call the API!
https://support.bittrex.com/hc/en-us/articles/115003723911-Developer-s-Guide-API
You'll probably want to use Guzzle, or cURL to make your requests. You can find lots of tutorials showing how to connect to any API using either.
This may or may not help you. A while back I started writing a library that hooked up to the BTC-e exchange (now Wex.nz). You can make adapters for any exchange, so you could tweak this code if you like.
https://github.com/delboy1978uk/BTCExchange/blob/master/src/Exchange/BtcE.php
Which extends this class https://github.com/delboy1978uk/BTCExchange/blob/master/src/Exchange/ExchangeAbstract.php
Credit to msg for bothering to check Packagist. There are many ready-to-rock Bittrex API packages waiting to be installed! https://packagist.org/?query=bitrex-api
Related
I was trying to parse the rss of the tag PHP, from http://stackoverflow.com and tried to use something other than DOM Model, So I looked into SimpleXML. THis is my code:
<?php
error_reporting(-1);
$xml = file_get_contents('https://stackoverflow.com/feeds/tag/php');
$loaded = simplexml_load_string($xml) or die("There is a problem");
$str1 = $loaded["entry"]["entry"][0]->title;
echo $str1;
?>
But nothing is displayed on the screen, and also no error is displayed!
The sample data from https://stackoverflow.com/feeds/tag/php can be found at
http://gourabt2.cloudapp.net/sample-data/sample_data.xml
Any Help would be very much appreciated! Thanks! Cheers!
You use array-access in SimpleXML to access attributes so:
$loaded["entry"]
returns the attribute named "entry" from the document element.
use arrow-access to get the element named "entry" instead:
$loaded->entry
this returns the element named "entry".
Additionally take care with namespaces. Parsing a feed with SimpleXML has been outlined already in existing Q&A material, please relate to it.
Try this out.
<?php
$xml = file_get_contents('http://stackoverflow.com/feeds/tag/php');
$loaded = simplexml_load_string($xml) or die("There is a problem");
foreach($loaded->entry as $post) {
echo $post->title . "\n";
}
Output:
join 2 tables - group by id order by date price asc
using php variable in an sql query
Clear browser cache memory by php code
There is a error in parsing the rss from stackoverflow.com. using SimpleXML in PHP
Modify Laravel Validation message response
chained dropdown from database
Php database handling
How to load model with Codeigniter Webservice - Nusoap Server?
multiple report download php adwords api
Unable to confirm Amazon SNS subscription for SES bounces
Comparing if values exist in database
Better way to CURL to WCF
PHP SaaS Facebook app: Host Page Tab ID and User ID
PHP and Mysql - running over PDOStatement
How to change form textbox value in Zend form annotation?
connect Android with PHP, MySQL , unfortunately app has stopped in android emulator
Auto increment a SESSION key ID
Call PHP function in a class from a HTML form
PHP SQL Preventing Duplicate User names: Catching Exception vs Select Query
I am only able to grab the first group of text in between the tr need helping fixing my code
How to run an external program in php
How to connect to php in android using an async task?
PHP Return HTML (Laravel / Lumen Framework)
prestashop smarty if statement
Cakephp OR condition Implementation
Progress bar HTML5/PHP
preg_match file url from jwplayer
Does Cloudflare Cache HTML5 Video Embedded on PHP Page?
how to INSERT INTO JOIN
PHP web service returns "403 forbidden" error
That's because you have the wrong path. Here is the correction.
(string)$loaded->entry->title;
Can someone help me I want to extract html data from http://www.quranexplorer.com/Hadith/English/Index.html. I have found a service that does exactly that http://diffbot.com/dev/docs/ they support data extraction via a simple api, the problem it that I have a large number of url that needs that needs to be processed. The link below http://test.deen-ul-islam.org/html/h.js
I need to create a script that that follows the url then using the api generate the json format of the html data (the apis from the site allows batch requests check website docs)
Please note diffbot only allows 10000 free request per month so I need a way to save the progress and be able to pick up where I left off.
Here is an example I created using php.
$token = "dfoidjhku";// example token
$url = "http://www.quranexplorer.com/Hadith/English/Hadith/bukhari/001.001.006.html";
$geturl="http://www.diffbot.com/api/article?tags=1&token=".$token."&url=".$url;
$json = file_get_contents($geturl);
$data = json_decode($json, TRUE);
echo $article_title=$data['title'];
echo $article_author=$data['author'];
echo $article_date=$data['date'];
echo nl2br($article_text=$data['text']);
$article_tags=$data['tags'];
foreach($article_tags as $result) {
echo $result, '<br>';
}
I don't mind if the tool is in javascript or php I just need a way to get the html data in json format.
John from Diffbot here. Note: not a developer, but know enough to write hacky code to do simple things.
You have a list of links -- it should be straightforward to iterate through those, making a call to us for each.
Here's a Python script that does such: https://gist.github.com/johndavi/5545375
I used a quick search regex in Sublime Text to pull out the links from the JS file.
To truncate this, just cut out some of the links, then run it. It will take a while as I'm not using the Batch API.
If you need to improve or change this, best seek out a stronger developer directly. Diffbot is a dev-friendly tool.
Im looking to pull a status field from a web management interface of a UPS so that the data could be utilised in another web application I am writing. I was wondering if anyone would know a way to go about this as I cant seem to find the information I'm looking for through my web searches. Id also need it the value to refresh or re check. Example of UPS web interface below looking at the online field first off:
This is a very basic example, that I haven't tested (php isnt installed).
You need to look at the source of your control panel, and find out how to identify the elements that contain your desired information.
The code below (hopefully) searches for an element with an id server-status if that element exists it then checks its class attribute to determine the state of the server.
You do not have to use the dom stuff, you could also do it with regex or whatever. So long as you can accurately find the information you need.
You may also need to use cURL or something a little more advanced than file_get_contents() as you will likely require login credentials to view the page in question.
<?php
$html = file_get_contents("http://path.to/your/control.panel");
// you may need to use cURL or something more advanced if you need to provide login credentials
$dom = new DOMDocument;
$dom->loadHTML($html);
$test = $dom->getElementById('server-status');
if ($test == NULL) {
// unable to find element, somethings up!
} else {
if ($test->getAttribute('class') == "online") {
// status element has "online" class, server is online
} else {
// status element does not have "online" class, somethings up!
}
}
?>
Update
Had a quick look at a demo of that management software and it wont be quite as simple as my example as there don't appear to be any helpful element id or class names. Its still do-able though.
I am trying to update a document in Couchbase 2.0 server using PHP API (php-ext-couchbase).
http://www.couchbase.com/docs/couchbase-sdk-php-1.1/api-reference-summary.html
The document is similar to facebook POSTS with comments and likes associated with it.
To be more specific.
-Load the doc.
-Modify it
-Store the modified doc if it has not been accessed by any other person.
Basic operations that would be required to accomplish this will be
# Get a document by key
doc = get(key)
# Modify a document when no one has modified it since my last read
casVersion = doc.getCas()
cas(key, casVersion, changedDoc)
I just want to know how i can accomplish this in PHP.
especially how to get the casVersion or the revision_id of the document and then further carry out the update process so that changes made by simultaneous updates on same document are not lost.
No worries I found it,
The code is
$bucket='yourbucketname';
$cb=new Couchbase("127.0.0.1:8091","root","password",$bucket);
$old_doc=null;
$cb->getDelayed($obj_id, true,
function($cb, $data) use (&$old_doc) { $old_doc = $data; });
$casKey=$old_doc['cas'];
Use getDelayed method, and callback function to get the array having (key,value,caskey)
I hope the couchbase documentation would be more clear in future with usages examples.
I wanted to use PHP Simple HTML DOM Parser to grab the Google Apps Status table so I can create my own dashboard that will only include Google Mail and Google Talk service status, as well as change the presentation (html,css).
As a test, I wanted to find/output the table element but it's not displaying any results.
$html = file_get_html('http://www.google.com/appsstatus');
$e = $html->find("table", 0);
echo $e->outertext;
Although, if I find/output the div elements it will display results.
$html = file_get_html('http://www.google.com/appsstatus');
$e = $html->find("div", 0);
echo $e->outertext;
Any help would be much appreciated.
It's way easier than that. All of this data is tied up in a JSON feed.
http://www.google.com/appsstatus/json/en
On a simple level, you could do a file_get_contents() of that, knock that bit off the front that says dashboard.jsonp, and then to a json_decode() (doc), and you will have yourself a nice array with all the information you'd ever want to know about Google's service status. Dump it with print_r() to see where everything is.
Finding these types of things is super easy with Fiddler. I highly recommend it.