0

Hola estoy tratando de traerme los datos json que aparecen esta página.

https://main.weku.io/@melodyne

la forma con la que intento traer los datos es:

    $link = 'https://main.weku.io/@melodyne';
    $link = strtolower($link);
    $link = strip_tags($link);
    $link = trim($link);

    $ch = curl_init($link);
    curl_setopt($ch,CURLOPT_ENCODING , "");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $jsonString = curl_exec($ch);
    curl_close($ch);
    $user_details = json_decode($jsonString, true);

    var_dump($user_details['global']);
}

Lo que obtengo al ejecutarlo:

NULL 

¿Ayuda?

2
  • te saldra nulll porque lo que recoje es html no json :V
    – Bryro
    el 8 dic. 2018 a las 17:14
  • como le hago papu ? :/ el 8 dic. 2018 a las 17:27

1 respuesta 1

0

Tienes que manejar lo retornado y representarlo como un documento HTML o XML en su totalidad, para lo cuál puedes usar DOMDocument de php. Luego para tomar el valor de un etiqueta en particular puedes usar getElementsByTagName:

<?
$link = 'https://main.weku.io/@melodyne';
$link = strtolower($link);
$link = strip_tags($link);
$link = trim($link);

$ch = curl_init($link);
curl_setopt($ch,CURLOPT_ENCODING , "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonString = curl_exec($ch);
curl_close($ch);

$doc = new DOMDocument();
@$doc->loadHTML($jsonString);
$nodes = $doc->getElementsByTagName('script');
$global = $nodes->item(0)->nodeValue; 

$user_details = json_decode($global, true);

//echo ''.$global;
var_dump($user_details['global']);

?>

Salida:

array(14) { ["current_route"]=> string(9) "@melodyne" ["discussion_idx"]=> array(0) { } ["accounts"]=> array(1) { ["melodyne"]=> array(71) { ["transfer_history"]=> array(0) { } ["last_bandwidth_update"]=> string(19) "2018-12-07T23:26:48" ["vesting_shares"]=> string(18) "55261.990454 VESTS" ["delegated_vesting_shares"]=> string(14) "0.000000 VESTS" ["savings_sbd_seconds_last_update"]=> string(19) "1970-01-01T00:00:00" ["posting"]=> array(3) { ["weight_threshold"]=> int(1) ["account_auths"]=> array(0) { } ["key_auths"]=> array(1) { [0]=> array(2) { [0]=> string(53) "WKA6WE7JWuKXDt36BmPzzXwmUTKA6LPy6tEQY8FBpVWwaUWpJDYaQ" [1]=> int(1) } } } ["reward_sbd_balance"]=> string(9) "0.000 WKD" ["blog"]=> array(3) { [0]=> string(13) "melodyne/test" [1]=> string(23) "melodyne/test-v2-script" [2]=> string(21) "melodyne/test-sccript" } ["witness_votes"]=> array(0) { } ["recovery_account"]=> string(9) "initminer" ["lifetime_market_bandwidth"]=> int(0) ["withdrawn"]=> int(0) ["last_account_update"]=> string(19) "2018-11-30T02:49:24" ["other_history"]=> array(0) { } ["json_metadata"]=> string(85) "{"profile":{"profile_image":"http://verfutbol.live/vendor/images/logo/melodyne.png"}}" ["active"]=> array(3) { ["weight_threshold"]=> int(1) ["account_auths"]=> array(0) { } ["key_auths"]=> array(1) { [0]=> array(2) { [0]=> string(53) "WKA6BCR9BuwD5ywqC7ghaTsaRUL9RWGwqfW5syhnjwMVCUDVeBU7P" [1]=> int(1) } } } ["posting_rewards"]=> int(0) ["vesting_withdraw_rate"]=> string(14) "0.000000 VESTS" ["guest_bloggers"]=> array(0) { } ["sbd_seconds_last_update"]=> string(19) "1970-01-01T00:00:00" ["created"]=> string(19) "2018-11-30T02:48:21" ["last_post"]=> string(19) "2018-12-07T23:26:27" ["savings_sbd_last_interest_payment"]=> string(19) "1970-01-01T00:00:00" ["name"]=> string(8) "melodyne" ["savings_sbd_balance"]=> string(9) "0.000 WKD" ["witnesses_voted_for"]=> int(0) ["owner_challenged"]=> bool(false) ["voting_power"]=> int(9800) ["to_withdraw"]=> int(0) ["proxy"]=> string(0) "" ["next_vesting_withdrawal"]=> string(19) "1969-12-31T23:59:59" ["vesting_balance"]=> string(10) "0.000 WEKU" ["average_bandwidth"]=> int(1241423327) ["savings_sbd_seconds"]=> string(1) "0" ["reward_vesting_steem"]=> string(10) "0.000 WEKU" ["comment_count"]=> int(0) ["post_count"]=> int(3) ["lifetime_vote_count"]=> int(0) ["average_market_bandwidth"]=> int(0) ["sbd_last_interest_payment"]=> string(19) "1970-01-01T00:00:00" ["last_account_recovery"]=> string(19) "1970-01-01T00:00:00" ["proxied_vsf_votes"]=> array(4) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) } ["mined"]=> bool(false) ["last_market_bandwidth_update"]=> string(19) "1970-01-01T00:00:00" ["market_history"]=> array(0) { } ["sbd_balance"]=> string(9) "0.000 WKD" ["owner"]=> array(3) { ["weight_threshold"]=> int(1) ["account_auths"]=> array(0) { } ["key_auths"]=> array(1) { [0]=> array(2) { [0]=> string(53) "WKA8iEQZuwt66tVq5W97yVWm7WLwCytSrYKV4cjijFHkuQzmWW4uw" [1]=> int(1) } } } ["savings_withdraw_requests"]=> int(0) ["last_root_post"]=> string(19) "2018-12-07T23:26:27" ["sbd_seconds"]=> string(1) "0" ["post_history"]=> array(0) { } ["savings_balance"]=> string(10) "0.000 WEKU" ["last_active_proved"]=> string(19) "1970-01-01T00:00:00" ["reputation"]=> string(11) "37618485231" ["last_vote_time"]=> string(19) "2018-12-07T23:26:48" ["can_vote"]=> bool(true) ["reward_steem_balance"]=> string(10) "0.000 WEKU" ["curation_rewards"]=> int(0) ["memo_key"]=> string(53) "WKA6KSuB5aofhenjcCjEqeiWPxZWmTXMkaxxLgfVPFp91LcSD5mm9" ["active_challenged"]=> bool(false) ["id"]=> int(51164) ["tags_usage"]=> array(0) { } ["lifetime_bandwidth"]=> int(1610000000) ["balance"]=> string(10) "0.000 WEKU" ["reset_account"]=> string(4) "null" ["last_owner_proved"]=> string(19) "1970-01-01T00:00:00" ["last_owner_update"]=> string(19) "1970-01-01T00:00:00" ["vote_history"]=> array(0) { } ["withdraw_routes"]=> int(0) ["received_vesting_shares"]=> string(21) "11000000.000000 VESTS" ["reward_vesting_balance"]=> string(14) "0.000000 VESTS" } } ["witnesses"]=> array(0) { } ["error"]=> string(0) "" ["feed_price"]=> array(2) { ["base"]=> string(9) "1.000 WKD" ["quote"]=> string(10) "1.000 WEKU" } ["community"]=> string(0) "" ["pow_queue"]=> array(0) { } ["pathname"]=> string(10) "/@melodyne" ["props"]=> array(29) { ["max_virtual_bandwidth"]=> string(21) "528482304000000000000" ["current_reserve_ratio"]=> int(200000000) ["virtual_supply"]=> string(18) "450216687.501 WEKU" ["confidential_supply"]=> string(10) "0.000 WEKU" ["num_pow_witnesses"]=> int(0) ["total_reward_fund_steem"]=> string(10) "0.000 WEKU" ["total_reward_shares2"]=> string(1) "0" ["pending_rewarded_vesting_shares"]=> string(24) "90620132058.886015 VESTS" ["sbd_interest_rate"]=> int(1000) ["head_block_id"]=> string(40) "0054da1ddb5e1ecc9fcf688d784fcdf7bbcdbc4d" ["time"]=> string(19) "2018-12-08T18:16:00" ["recent_slots_filled"]=> string(39) "340282366920938463463374607431768211455" ["confidential_sbd_supply"]=> string(9) "0.000 WKD" ["participation_count"]=> int(128) ["vote_power_reserve_rate"]=> int(10) ["maximum_block_size"]=> int(131072) ["current_witness"]=> string(9) "initminer" ["current_supply"]=> string(18) "448397591.959 WEKU" ["average_block_size"]=> int(736) ["pending_rewarded_vesting_steem"]=> string(16) "1605938.355 WEKU" ["current_aslot"]=> int(6375920) ["total_vesting_fund_steem"]=> string(17) "79967287.681 WEKU" ["head_block_number"]=> int(5560861) ["id"]=> int(0) ["last_irreversible_block_num"]=> int(5560861) ["sbd_print_rate"]=> int(10000) ["total_vesting_shares"]=> string(26) "4415198913852.505927 VESTS" ["total_pow"]=> string(20) "18446744073709551615" ["current_sbd_supply"]=> string(15) "1819095.542 WKD" } ["tag_idx"]=> array(1) { ["trending"]=> array(50) { [0]=> string(0) "" [1]=> string(15) "community-deals" [2]=> string(4) "amar" [3]=> string(7) "zealpro" [4]=> string(4) "weku" [5]=> string(11) "photography" [6]=> string(4) "life" [7]=> string(13) "wekuteamworld" [8]=> string(11) "teamquality" [9]=> string(14) "wekubangladesh" [10]=> string(5) "nirob" [11]=> string(7) "created" [12]=> string(7) "spanish" [13]=> string(8) "acehnese" [14]=> string(4) "blog" [15]=> string(6) "nature" [16]=> string(4) "aceh" [17]=> string(4) "news" [18]=> string(4) "zeal" [19]=> string(7) "writing" [20]=> string(3) "art" [21]=> string(8) "phoketoz" [22]=> string(5) "lifty" [23]=> string(4) "food" [24]=> string(9) "whitelist" [25]=> string(9) "indonesia" [26]=> string(5) "story" [27]=> string(5) "photo" [28]=> string(6) "saahil" [29]=> string(10) "wekufamily" [30]=> string(6) "flower" [31]=> string(11) "weku-create" [32]=> string(9) "weku-team" [33]=> string(6) "poetry" [34]=> string(7) "bitcoin" [35]=> string(11) "phototalent" [36]=> string(14) "cryptocurrency" [37]=> string(8) "wekuteam" [38]=> string(7) "monomad" [39]=> string(12) "weku-nigeria" [40]=> string(8) "weku-edu" [41]=> string(6) "travel" [42]=> string(4) "love" [43]=> string(8) "wekulife" [44]=> string(6) "sports" [45]=> string(18) "zeal-gratefulvibes" [46]=> string(19) "photo-wekuteamworld" [47]=> string(7) "qurator" [48]=> string(19) "story-wekuteamworld" [49]=> string(7) "contest" } } ["tags"]=> array(0) { } ["content"]=> array(3) { ["melodyne/test"]=> array(45) { ["parent_author"]=> string(0) "" ["pending_payout_value"]=> string(9) "0.603 WKD" ["curator_payout_value"]=> string(9) "0.000 WKD" ["root_comment"]=> int(806660) ["body"]=> string(12) "testscript 3" ["body_length"]=> int(0) ["max_accepted_payout"]=> string(15) "1000000.000 WKD" ["beneficiaries"]=> array(0) { } ["depth"]=> int(0) ["promoted"]=> string(9) "0.000 WKD" ["net_rshares"]=> string(12) "802896193676" ["reblogged_by"]=> array(0) { } ["json_metadata"]=> string(75) "{"tags":["community-deals","test"],"app":"steemit/0.1","format":"markdown"}" ["active"]=> string(19) "2018-12-07T23:26:27" ["net_votes"]=> int(2) ["replies"]=> array(0) { } ["reward_weight"]=> int(10000) ["created"]=> string(19) "2018-12-07T23:26:27" ["percent_steem_dollars"]=> int(10000) ["permlink"]=> string(4) "test" ["author"]=> string(8) "melodyne" ["max_cashout_time"]=> string(19) "1969-12-31T23:59:59" ["author_reputation"]=> string(11) "37618485231" ["url"]=> string(31) "/community-deals/@melodyne/test" ["last_payout"]=> string(19) "1970-01-01T00:00:00" ["active_votes"]=> array(0) { } ["author_rewards"]=> int(0) ["allow_curation_rewards"]=> bool(true) ["cashout_time"]=> string(19) "2018-12-14T23:26:27" ["vote_rshares"]=> string(12) "802896193676" ["total_vote_weight"]=> int(907138) ["allow_replies"]=> bool(true) ["last_update"]=> string(19) "2018-12-07T23:26:27" ["allow_votes"]=> bool(true) ["total_payout_value"]=> string(9) "0.000 WKD" ["title"]=> string(4) "test" ["abs_rshares"]=> string(12) "802896193676" ["children_abs_rshares"]=> string(12) "802896193676" ["root_title"]=> string(4) "test" ["id"]=> int(806660) ["total_pending_payout_value"]=> string(10) "0.000 WEKU" ["category"]=> string(15) "community-deals" ["stats"]=> array(9) { ["isNsfw"]=> bool(false) ["hide"]=> bool(false) ["hasPendingPayout"]=> bool(true) ["gray"]=> bool(false) ["flagWeight"]=> int(0) ["up_votes"]=> int(2) ["total_votes"]=> int(2) ["authorRepLog10"]=> int(39) ["allowDelete"]=> bool(false) } ["children"]=> int(0) ["parent_permlink"]=> string(15) "community-deals" } ["melodyne/test-sccript"]=> array(45) { ["parent_author"]=> string(0) "" ["pending_payout_value"]=> string(9) "0.602 WKD" ["curator_payout_value"]=> string(9) "0.000 WKD" ["root_comment"]=> int(800490) ["body"]=> string(126) "Este es un script de prueba. no votar estar publicacion gracias.   This is a test script. do not vote be published thank you." ["body_length"]=> int(0) ["max_accepted_payout"]=> string(15) "1000000.000 WKD" ["beneficiaries"]=> array(0) { } ["depth"]=> int(0) ["promoted"]=> string(9) "0.000 WKD" ["net_rshares"]=> string(12) "801790667477" ["reblogged_by"]=> array(0) { } ["json_metadata"]=> string(75) "{"tags":["community-deals","test"],"app":"steemit/0.1","format":"markdown"}" ["active"]=> string(19) "2018-12-06T18:10:03" ["net_votes"]=> int(2) ["replies"]=> array(0) { } ["reward_weight"]=> int(10000) ["created"]=> string(19) "2018-12-06T18:10:03" ["percent_steem_dollars"]=> int(10000) ["permlink"]=> string(12) "test-sccript" ["author"]=> string(8) "melodyne" ["max_cashout_time"]=> string(19) "1969-12-31T23:59:59" ["author_reputation"]=> string(11) "37618485231" ["url"]=> string(39) "/community-deals/@melodyne/test-sccript" ["last_payout"]=> string(19) "1970-01-01T00:00:00" ["active_votes"]=> array(0) { } ["author_rewards"]=> int(0) ["allow_curation_rewards"]=> bool(true) ["cashout_time"]=> string(19) "2018-12-13T18:10:03" ["vote_rshares"]=> string(12) "801790667477" ["total_vote_weight"]=> int(906611) ["allow_replies"]=> bool(true) ["last_update"]=> string(19) "2018-12-06T18:10:03" ["allow_votes"]=> bool(true) ["total_payout_value"]=> string(9) "0.000 WKD" ["title"]=> string(12) "test sccript" ["abs_rshares"]=> string(12) "801790667477" ["children_abs_rshares"]=> string(12) "801790667477" ["root_title"]=> string(12) "test sccript" ["id"]=> int(800490) ["total_pending_payout_value"]=> string(10) "0.000 WEKU" ["category"]=> string(15) "community-deals" ["stats"]=> array(9) { ["isNsfw"]=> bool(false) ["hide"]=> bool(false) ["hasPendingPayout"]=> bool(true) ["gray"]=> bool(false) ["flagWeight"]=> int(0) ["up_votes"]=> int(2) ["total_votes"]=> int(2) ["authorRepLog10"]=> int(39) ["allowDelete"]=> bool(false) } ["children"]=> int(0) ["parent_permlink"]=> string(15) "community-deals" } ["melodyne/test-v2-script"]=> array(45) { ["parent_author"]=> string(0) "" ["pending_payout_value"]=> string(9) "0.603 WKD" ["curator_payout_value"]=> string(9) "0.000 WKD" ["root_comment"]=> int(805977) ["body"]=> string(41) "TEST V2 SCRIPT DONT VOTE THIS POST THANKS" ["body_length"]=> int(0) ["max_accepted_payout"]=> string(15) "1000000.000 WKD" ["beneficiaries"]=> array(0) { } ["depth"]=> int(0) ["promoted"]=> string(9) "0.000 WKD" ["net_rshares"]=> string(12) "802896193676" ["reblogged_by"]=> array(0) { } ["json_metadata"]=> string(77) "{"tags":["community-deals","script"],"app":"steemit/0.1","format":"markdown"}" ["active"]=> string(19) "2018-12-07T19:03:00" ["net_votes"]=> int(2) ["replies"]=> array(0) { } ["reward_weight"]=> int(10000) ["created"]=> string(19) "2018-12-07T19:03:00" ["percent_steem_dollars"]=> int(10000) ["permlink"]=> string(14) "test-v2-script" ["author"]=> string(8) "melodyne" ["max_cashout_time"]=> string(19) "1969-12-31T23:59:59" ["author_reputation"]=> string(11) "37618485231" ["url"]=> string(41) "/community-deals/@melodyne/test-v2-script" ["last_payout"]=> string(19) "1970-01-01T00:00:00" ["active_votes"]=> array(0) { } ["author_rewards"]=> int(0) ["allow_curation_rewards"]=> bool(true) ["cashout_time"]=> string(19) "2018-12-14T19:03:00" ["vote_rshares"]=> string(12) "802896193676" ["total_vote_weight"]=> int(907138) ["allow_replies"]=> bool(true) ["last_update"]=> string(19) "2018-12-07T19:03:00" ["allow_votes"]=> bool(true) ["total_payout_value"]=> string(9) "0.000 WKD" ["title"]=> string(14) "TEST V2 SCRIPT" ["abs_rshares"]=> string(12) "802896193676" ["children_abs_rshares"]=> string(12) "802896193676" ["root_title"]=> string(14) "TEST V2 SCRIPT" ["id"]=> int(805977) ["total_pending_payout_value"]=> string(10) "0.000 WEKU" ["category"]=> string(15) "community-deals" ["stats"]=> array(9) { ["isNsfw"]=> bool(false) ["hide"]=> bool(false) ["hasPendingPayout"]=> bool(true) ["gray"]=> bool(false) ["flagWeight"]=> int(0) ["up_votes"]=> int(2) ["total_votes"]=> int(2) ["authorRepLog10"]=> int(39) ["allowDelete"]=> bool(false) } ["children"]=> int(0) ["parent_permlink"]=> string(15) "community-deals" } } ["witness_schedule"]=> array(15) { ["next_shuffle_block_num"]=> int(5560843) ["timeshare_weight"]=> int(5) ["current_virtual_time"]=> string(1) "0" ["max_voted_witnesses"]=> int(20) ["max_miner_witnesses"]=> int(0) ["witness_pay_normalization_factor"]=> int(1) ["majority_version"]=> string(6) "0.20.0" ["max_runner_witnesses"]=> int(1) ["miner_weight"]=> int(1) ["hardfork_required_witnesses"]=> int(1) ["current_shuffled_witnesses"]=> string(672) "656e696d74696e6900000000000000720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ["top19_weight"]=> int(1) ["id"]=> int(0) ["median_props"]=> array(3) { ["account_creation_fee"]=> string(10) "0.001 WEKU" ["maximum_block_size"]=> int(131072) ["sbd_interest_rate"]=> int(1000) } ["num_scheduled_witnesses"]=> int(1) } }
5
  • si ya se que concatenandole el .json te da esos datos json. pero de esta forma te los da incompletos. si te fijas en el surce de la pagina que pongo hay un array ['global'] toda esa info es la que necesito. el 8 dic. 2018 a las 17:33
  • esto es lo que necesito. oi66.tinypic.com/f42uiu.jpg el 8 dic. 2018 a las 17:42
  • Ahí edité mi respuesta.
    – Mario L
    el 8 dic. 2018 a las 18:20
  • 7u7r ahora si gracias papu!! el 8 dic. 2018 a las 18:38
  • Hola una ultima consulta. para traer los datos de json_metadata como le hago? intento var_dump($user_details['global']['accounts']['json_metadata']); pero sale Undefined index: json_metadata el 10 dic. 2018 a las 1:17

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.