"Beautiful soup" question!

Asked 2 years ago, Updated 2 years ago, 356 views

Hi, everyone. I'm leaving a question because I got stuck while crawling Python.

We found a specific class and found the value below.

stock = soup3.find('div',{'id':'layout_config_full'})



#Result
<div class="flying" id="layout_config_full">
<img alt="" src="../images/.jpg" title=""/>
<script src="/app/javascript/js/goods-view.js?dummy=20221025011708" type="text/javascript">    </script>
<script src="/app/javascript/plugin/jquery.inview.js" type="text/javascript"></script>
<script type="text/javascript">
var gl_goods_price                  = 0;
var gl_event_sale_unit              = 0;
var gl_cutting_sale_price           = 0;
var gl_cutting_sale_action          = "dscending";
var gl_multi_discount_use           = "";
var gl_multi_discount_unit          = "";
var gl_multi_discount               = 0;
var gl_multi_discount_ea            = 0;
var gl_option_view_type             = "divide";
var gl_options_count                = 4;
var gl_opttag                       = '<tr class="quanity_row">';
var gl_min_purchase_limit           = 'unlimit';
var gl_min_purchase_ea              = 0;
var gl_max_purchase_limit           = 'unlimit';
var gl_max_purchase_ea              = 0;
var gl_member_seq                   = "15017";
var gl_request_uri                  = "%2Fgoods%2Fview%3Fno%3D153";
var gl_goods_seq                    = 0;
var gl_option_divide_title_count    = 1;
var gl_skin                         = "beauty_nature_gls";
var gl_string_price_use             = "";
var gl_string_button_use            = "";

var gl_option_n0 = [{"opt":"\uc815\uc0ac\uac01 \ud654\uc774\ud2b8","stock":"0","price":11970,"consumer_price":"0.00","reservation":0,"infomation":"","color":"","zipcode":null,"address_type":null,"address":null,"addressdetail":null,"address_street":null,"newtype":"none","codedate":null,"sdayinput":null,"fdayinput":null,"dayauto_type":null,"sdayauto":null,"fdayauto":null,"dayauto_day":null,"biztel":null,"coupon_input":"0","package_option_seq1":null,"package_option_seq2":null,"package_option_seq3":null,"package_option_seq4":null,"package_option_seq5":null,"package_option1":null,"package_option2":null,"package_option3":null,"package_option4":null,"package_option5":null,"option_seq":"5095","goods_seq":"153","package_error":false,"chk_stock":false,"ori_price":11970,"opspecial_location":{"none":1}},{"opt":"\uc815\uc0ac\uac01 \ud551\ud06c","stock":"997","price":11970,"consumer_price":"0.00","reservation":0,"infomation":"","color":"","zipcode":null,"address_type":null,"address":null,"addressdetail":null,"address_street":null,"newtype":"none","codedate":null,"sdayinput":null,"fdayinput":null,"dayauto_type":null,"sdayauto":null,"fdayauto":null,"dayauto_day":null,"biztel":null,"coupon_input":"0","package_option_seq1":null,"package_option_seq2":null,"package_option_seq3":null,"package_option_seq4":null,"package_option_seq5":null,"package_option1":null,"package_option2":null,"package_option3":null,"package_option4":null,"package_option5":null,"option_seq":"5096","goods_seq":"153","package_error":false,"chk_stock":true,"ori_price":11970,"opspecial_location":{"none":1}},{"opt":"\ubb3c\uacb0 \ud654\uc774\ud2b8","stock":"0","price":19970,"consumer_price":"0.00","reservation":0,"infomation":"","color":"","zipcode":null,"address_type":null,"address":null,"addressdetail":null,"address_street":null,"newtype":"none","codedate":null,"sdayinput":null,"fdayinput":null,"dayauto_type":null,"sdayauto":null,"fdayauto":null,"dayauto_day":null,"biztel":null,"coupon_input":"0","package_option_seq1":null,"package_option_seq2":null,"package_option_seq3":null,"package_option_seq4":null,"package_option_seq5":null,"package_option1":null,"package_option2":null,"package_option3":null,"package_option4":null,"package_option5":null,"option_seq":"5097","goods_seq":"153","package_error":false,"chk_stock":false,"ori_price":19970,"opspecial_location":{"none":1}},{"opt":"\ubb3c\uacb0 \ud551\ud06c","stock":"990","price":19970,"consumer_price":"0.00","reservation":0,"infomation":"","color":"","zipcode":null,"address_type":null,"address":null,"addressdetail":null,"address_street":null,"newtype":"none","codedate":null,"sdayinput":null,"fdayinput":null,"dayauto_type":null,"sdayauto":null,"fdayauto":null,"dayauto_day":null,"biztel":null,"coupon_input":"0","package_option_seq1":null,"package_option_seq2":null,"package_option_seq3":null,"package_option_seq4":null,"package_option_seq5":null,"package_option1":null,"package_option2":null,"package_option3":null,"package_option4":null,"package_option5":null,"option_seq":"5098","goods_seq":"153","package_error":false,"chk_stock":true,"ori_price":19970,"opspecial_location":{"none":1}}];

I want to get only the stock value for gl_option_n0 here00. "stock":"0", "stock":"999", etc. There are times when there is only one.

How can I find it with select or find to get stock only?

Thank you again for sharing your knowledge.

python beautifulsoup

2022-10-25 11:41

1 Answers

import json
a = stock.replace(' ', '').split('gl_option_n0=')[1].split(';')[0]
b = json.loads(a)
b['stock']


2022-10-25 11:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.