HTML Javascript文本输出上的Xpath文本选择器

时间:2018-04-01 11:02:17

标签: html xpath extractor

我是Xpath的新手,目前正致力于通过以下链接提取数据:

https://www.ikea.com/us/en/catalog/products/60203330/

如下所示的Xpath会将所有文本值打印为代码段中的代码。

是否有任何额外的XPath可以添加以解压缩javascript文本输出var jProductData?

//*[@id="mainPadding"]/script[3]/text()

<script type="text/javascript" language="JavaScript">
				var MODELS = "Models";
				var js_fn_MAX_NO_OF_LISTS = "10";
				var js_ECOM_ENABLED = true;
				var MOST_LIKELY_IN_STOCK = "Currently in stock at";
				var PROBABLY_IN_STOCK = "Probably in stock at";
				var SMALL_CHANCE_IN_STOCK = "Small chance of being in stock at";
				var AVAILABLE_BY_ORDER = "Only available by order with delivery where delivery fees apply at";
				var NOT_IN_STOCK = "Not in stock at";
				var NOT_FOR_SALE = "Not for sale at";
				var SERVICE_UNAVAILABLE = "Stock information is temporarily unavailable.<br> Please try again later.";
				var FOOD_STOCK_DATA_UNAVAILABLE = "No stock information is available for IKEA food products, please check in store.";
				var IKEA = "IKEA";
				var BRAND = "IKEA";
				var highChanceInfoBar = "/ms/img/static/stock_check_green.gif";
				var probablyInfoBar = "/ms/img/static/stock_check_yellow.gif";
				var smallChanceInfoBar = "/ms/img/static/stock_check_red.gif";
				var stockCheckChoice = "false";
				var showFoodStockDataUnavailableMsg = false;
				var jProductData = {"product":{"items":[{"custMaterials":"100 % polyester<br/>","descriptiveAttributes":{},"imperial":"Length: 71 \"<br/>Width: 71 \"<br/>Area: 34.88 sq feet<br/><br/>","catEntryId":"649380","dualCurrencies":false,"pkgInfoArr":[{"articleNumber":"60203330","pkgInfo":[{"heightImp":"¾ &#34;","weightImp":"15 oz","weightMet":"0.43 kg","widthImp":"5 &#34;","widthMet":"13 cm","quantity":"1","consumerPackNo":1,"lengthImp":"9 ¾ &#34;","lengthMet":"25 cm","heightMet":"2 cm"}]}],"type":"Shower curtain","reqAssembly":false,"soldSeparately":"","name":"SALTGRUND","bti":false,"attachments":[],"partNumber":"60203330","avg_rating":"5","validDesign":["gray"],"goodToKnowPIP":"To be completed with shower curtain rings and a shower curtain rod.<br/>","techInfoArr":[],"careInst":"Machine wash warm, normal cycle.<br/>Do not bleach.<br/>Do not tumble dry.<br/>Iron low.<br/>To retain water repellence, iron after washing.<br/>Do not dry clean.<br/>","extendedContext":[{"articleNumber":"60203330","extendedContext":[{"avg_rating":"5","rating_count":"3","gprAvgRating":"5","gprRatingCount":"3"}]}],"designer":"Emma Jones","nopackages":"1","goodToKnow":"To be completed with shower curtain rings and a shower curtain rod.<br/>","url":"/us/en/catalog/products/60203330/","packagePopupUrl":"/us/en/catalog/packagepopup/60203330/","availabilityUrl":"/us/en/catalog/availability/60203330/","environment":"No perfluorinated chemicals (e.g. PFOS, PFOA, PFOSA) are used to make this product water repellent. As perfluorinated chemicals are non-degradable, it\u2019s better for you and the environment to avoid them.<br/>The material in this product MAY BE recyclable. Please check the recycling rules in your community and if recycling facilities exist in your area.<br/>Non-chlorine bleach.<br/>No optical brightener has been used.<br/>","rating_count":"3","color":"gray","custBenefit":"<cbs><cb><t>Two-sided woven polyester which gives a soft fall and a decorative pattern on both sides.<\/t><\/cb><cb><t>Densely-woven polyester fabric with water-repellent coating.<\/t><\/cb><\/cbs>","metric":"Length: 180 cm<br/>Width: 180 cm<br/>Area: 3.24 m²<br/><br/>","buyable":true,"prices":{"comparisonPriceExists":false,"hasTemporaryFamilyOffer":false,"hasFamilyPrice":false,"usesUnitPriceMeasure":false,"isUnitPricePrimary":false,"normal":{"priceNormal":{"priceExclVat":"$14.99","value":"$14.99","rawPrice":14.99},"priceNormalDual":{},"priceNormalPerUnit":{"unit":""}},"hasEcoFee":false,"enablenlpinterval":0,"hasPrfCharge":false},"images":{"zoom":["/PIAimages/0307519_PE427662_S5.JPG","/PIAimages/0406033_PE566947_S5.JPG","/PIAimages/0406724_PE567270_S5.JPG"],"normal":["/PIAimages/0307519_PE427662_S3.JPG","/PIAimages/0406033_PE566947_S3.JPG","/PIAimages/0406724_PE567270_S3.JPG"],"thumb":["/PIAimages/0307519_PE427662_S2.JPG"],"small":["/PIAimages/0307519_PE427662_S1.JPG"],"large":["/us/en/images/products/saltgrund-shower-curtain-gray__0307519_PE427662_S4.JPG","/us/en/images/products/saltgrund-shower-curtain-gray__0406033_PE566947_S4.JPG","/us/en/images/products/saltgrund-shower-curtain-gray__0406724_PE567270_S4.JPG"]},"californiaTitle20Product":false}],"catEntryId":"3260697","attributes":[{"id":"8556332","name":"color","type":"00018"},{"id":"8556333","name":"size","type":"00019"}],"partNumber":"25464 [GENERICPRODUCT]"}};				
				var jsonProduct = jProductData.product;	
				var jCatEntryId = jsonProduct.catEntryId;
				var jPartNumber = jsonProduct.partNumber;
				var storeBaseURL = "/us/en/store/";
				var PD_txt_bvDown = "We’re having some technical problems and are working on a solution. Sorry for the inconvenience.";
				var weee_lessPrf = "Less PRF ";
				var weee_prf = "PRF";
				var packageText = "Show dimensions, weight and article numbers";				
				var singlePackage = "Package";
 			    var multiplePackage = "Packages";
				var showAll = "Show all";
				var showLess = "Show less";	
				var readMore = "Read more";
				var pricePerPackage = "Price/pk";
				var pricePer = "Price per";
				var ikeaFamily ="IKEA FAMILY member price"; 
				var ikeaRegular ="Regular price"; 
     				var storeId="12";
     				var langId="-1";     
				var currentItem = "60203330";
				var localeJs = "en_US";
				var width = "Width:";
				var articleNo = "Article Number:"
				var height = "Height:";
				var length = "Length:"
				var weight = "Weight:"
				var diameter = "Diameter:"
				var quantity = "Quantity:";
				var packages = "Packages";
				var widthTitle = "Width";
				var articleNoTitle = "Article Number"
				var heightTitle = "Height";
				var lengthTitle = "Length"
				var weightTitle = "Weight"
				var diameterTitle = "Diameter"				
				var packageMeasures = "Package measurement &amp; weight"
				var cm = "cm";
				var kg = "kg";
				var californiaLegalText = "In compliance with California Title 20 regulations, product prices and features may vary in the state of California.";
				var californiaUrlText = "Please see your local store for details";
				var californiaUrlRef = "http://info.ikea-usa.com/StoreLocator/StoreLocator.aspx";
				var californiaMoreInfo = "More information";
				var unitPriceTxt = "Unit price"
				var displayManySameProduct = "false";
				var moreText = "more";
                			var smallNewImg = '/ms/en_US/img/icons/new_small.gif';
               			var newImg = '/ms/en_US/img/icons/new_large.gif';
               			var newImgAlt = 'NEW';
                			
                			var nlpImg = '/ms//img/nlp/en_US/nlp_04.png';
                			var nlpPopupImgSrc = '/ms//img/nlp/en_US/nlp_02.png';
                			var nlpImgAlt = 'New Lower Price';
                			var assemblyInstructions = 'Assembly instructions';
                			var article = "Article";
				var pdf = "PDF";
				var download = "Download";
				var assemblyProdInfo = "Download assembly instructions.";
				var notice = "Please note that the stock can be different if checked outside of";
				var storehours = "store opening hours";
				var invalidDIFAttr = "[00019, 00033, 00029, 13622, 00028]";
				var moreProdBaseUrl = "/us/en/iows/catalog/products/";
				var packageHeader = "Package measurements and weight"

				var sscCatalogId = "";
				var sscCategory = "";
				var simsCategory = "18908";
				var simsCatalogId = "departments";
				var depthInFunctionCategory = "";
				
				var itemProperties = new Array("name","type","productTypeProdInfo" ,"itemNumber","FAcode");
				var productDetails = new Array("packageInfo","nopackages","custMaterials","imperial","metric","careInst","goodToKnowPIP","environment","custBenefit","designer","salesArg","downloadAssembly","downloadAssemblyProdInfo","designerThoughts","lowestPrice","soldSeparately");
				var priceProperties = new Array("price1", "price5" , "price6" ,"price1perunit","storeformatpieces","storeformatpieces2","price2","packUnitPrice","packUnitPrice2","packUnitPrice5","packUnitPrice6","prfCharge","ecoFee","priceProdInfo","troPrice","familystoreformatpieces","mainPriceExclVat","nlpPrice","familyDate");							
				var notAvailable = new String("(Not available)");					
				var stockCheckServiceURL = "/us/en/iows/catalog/availability/";
				var isDIFEnabled = true;
				var measFlag = "2";
				var nlpPrevPriceCrossOverEnabled = true;
				var troPrevPriceCrossOverEnabled = true;
				var troDisclaimer = "While supplies last in participating US stores. ";
				var insteadOf = "was";				
				var quality ="Everyday quality"
				var energyAndResources ="Energy & Resources"
				var sustainableLifeAtHome ="Sustainable life at home"
				var peopleAndCommunication ="People & Communities"
				var material ="Material matters"
				var formDesignProcess ="Behind the design"
				var functionSolution ="Smart functions"				
				var designerThoughts ="Designer thoughts"
				var designer ="Designer:"
				var zoomText ="Click here for zoom"	
				
				var jsonRelatedProducts = {"item_60203330":{"WPP_COMPLEMENTARY_CONTAINER":[[]],"MAY_BE_COMPLETED_WITH":["23102900"]}};
				var productsBaseUrl = "/us/en/catalog/products/";
				var showWeeeRelatedData = false;				
				var viewComplementaryProdsText = "View all coordinating products";
				var mustBeCompletedTxtOne = "Remember to complete {0} with the following product";
				var mustBeCompletedTxtMany = "Remember to complete {0} with the following {1} products";
				var complementaryProdsTxt = "Coordinating Products";				
				var soldSeparatelyTxt = "&nbsp;";
				var soldSeparatelyDesc = '';
				var soldSeparatelyFlag = "false";
				var itemRelationValue = irwstatGetTrailingTagValue('IRWStats.productFindingMethod');
				var baseURL = "/us/en/catalog/products/";				
				var altImgFlag = "true";
				var zoomImageFlag = "true";
				var localPriceFlag = "false";
				var okButton = "OK"
				var notifiyError = "&nbsp;"
				var localStoreList = "209|tempe:399|burbank:162|carson:167|costa_mesa:413|covina:347|east_palo_alto:165|emeryville:166|san_diego:157|west_sacramento:064|centennial:213|new_haven:537|jacksonville:327|miami:145|orlando:207|sunrise:042|tampa:257|atlanta:170|bolingbrook:210|schaumburg:536|fishers:374|merriam:158|stoughton:152|baltimore:411|college_park:026|canton:212|twin_cities:410|st_louis:067|charlotte:154|elizabeth:409|paramus:462|las_vegas:921|brooklyn:156|long_island:511|columbus:175|west_chester:028|portland:211|conshohocken:153|pittsburgh:215|philadelphia:508|memphis:183|frisco:535|grand_prairie:379|houston:027|round_rock:103|draper:168|woodbridge:488|seattle";
				var assembly_inst_type = "ASSEMBLY_INSTRUCTIONS";
				var atchSummaryUsgTypes = ["GUARANTEE","ASSEMBLY_INSTRUCTIONS","MANUALS","SOFTWARE_DOWNLOADS","DEC_OF_CONFORMITY"];
				var attachmentHeadline = "Instructions & other documents";
				var attachmentDocumentsTxt = "Downloads for this product:";
				var attachmentDownloads = "Downloads";
				var attachmentDisclaimer = "Only the latest version of the documents is available for download. This means that there maybe a difference in this version and the printed version.";
				var faqHeading = "FAQ & Contact Us";
				var faqContactUsHeadline = "Any questions?";
				var faqContactUsLinkTxt = "Contact Us";
				var faqContactUsLink = "https://www.ikea.com/ms/en_US/customer_service/contact_us/contact.html";
				var priceText = "Price/";
				var displayUnit = "";
				var showPriceExclVat = false;
				var exclVatText = "&nbsp;";
				var datePattern = "";
				uniqueUrl.updateProductMetaTag();
			</script>

感谢您的观看。

1 个答案:

答案 0 :(得分:0)

使用

const puppeteer = require('puppeteer');

(async () => {

    const browser = await puppeteer.launch({headless: true});
    const page = await browser.newPage();

    await page.goto('https://www.ikea.com/us/en/catalog/products/60203330/');

    const result = await page.evaluate(() => {
        return window.jProductData;
    });

    console.log(JSON.stringify(result, null, 4));
    await browser.close();

})();

输出:

{
    "product": {
        "items": [
            {
                "custMaterials": "100 % polyester<br/>",
                "descriptiveAttributes": {},
                "imperial": "Length: 71 \"<br/>Width: 71 \"<br/>Area: 34.88 sq feet<br/><br/>",
                "catEntryId": "649380",
                "dualCurrencies": false,
                "pkgInfoArr": [
                    {
 ...