因此,我正在尝试将视频的Facebook观看次数导入电子表格。但是该类在注释代码中,因此没有任何反应!这是公式:
=importXML(A1,"//span[@class='fcg']")
如何在评论中找到该选择器的XPath?
更新:
这里是被注释的部分,其中是我尝试使用XPath的“ fcg”类:
<div class="hidden_elem"><code id="u_0_17"><!-- <div class="_5pcb _3z-f __b4" data-testid="newsFeedStream"><div role="feed"><div class="_4-u2 mbm _4mrt _5jmm _5pat _5v3q _7cqq _5uun _4-u8" data-ft="{"fbfeed_location":120}" data-fte="1" data-ftr="1" data-xt="AZUuaDOJ68qL3uUVCMKQAiaQnlOQOe7qCbE5OyvVyP-wKj3dsUxkyU-OzSfhq3CJyD11H7P0SxFlc4xkToZfFLdFsAEsEK9H7j5HDNIpeDpwips9aCQ-joTsg6Syh5fwuLcjRDW9XzmrLReAINq5by8gL5UB92gC5FtzWVy9Ozwwu2zJgMYvilfVCflx162NIGKl-9lX_Q50UlcdyUnkoSDEAP8XyJkl4C-4ZoE5HqSEGmn_7S-sHP-WbYNAEFEXAevGrGg1Qkx_J7bcvIvKnDI1wbkTOnvq5kbfqabgeg8HShqD0IXvHDR9Pg8VYe-u1XA5NG5FeOdDV1I9D_TtYcualelFsc79QayGXeEnJK76qJumio00jwt-1i7vGQw7Y2IkDxvqqqFqJ6XWfoR5VbscG2xFWXKmZr4M6iVBbL9FI2hPTNhrXzYYV8zJqNA74Fr0IumXDvmFqHRbS_Pq2SYo1oKJjRkPdk5fCNjyzII0KD8MyXMg7HNbYbUNoFr1BHwySGgUuZABvEd7v92g-b00pn8me42xVxKoYLQzBolwdi3yvnPUggfabfq3g83q2xzplk3psdisMdNHfbWjmJdDSWj-J-9Fl3T9jj5yfiWV7tQxGPRbvj37Ah7YUdQLhSdJcj14eazzvxvqKPF3QuuX6Ce-8q8w64Accd9-YJ37BN39n1i4C_JeFW7hsRZFDk9SoIAuwIBwEEbjc-sSvCAiLDVWuPLw-wNdxrRtPKnN3GHSASzsxQeJFUKYqJi_Huq5Ngy-_TIqzp8wtl1CwFD6u_XoLbFlzlZ8lxajtF1WNUEIiyOGP1wNNQPoa3herULaOqZ-7nEK0HhsrLY7q35m" data-xt-vimp="{"pixel_in_percentage":1,"duration_in_ms":1,"subsequent_gap_in_ms":60000,"log_initial_nonviewable":false,"should_batch":true,"require_horizontally_onscreen":false,"encrypt_data_xt":true,"signal_mode_for_ss":false,"vital_mode_for_ss":false,"should_not_delay_impression":true}" data-testid="fbfeed_story" id="u_0_12"><div class="_3ccb" data-ft="{"tn":"-R"}" data-gt="{"type":"click2canvas","fbsource":703,"ref":"nf_generic"}" id="u_0_13"><div></div><div></div><div class="_5pcr userContentWrapper" style="" data-ft="{"tn":"-R"}"><div class="_1dwg _1w_m _q7o"><div class="_4r_y"><div class="_1wbl"></div></div><div><span class="_47we _42b7"></span><div class="l_c3pyo2v0u i_c3pynyi2f clearfix"><div class="clearfix y_c3pyo2ta3"><a class="_5pb8 o_c3pynyi2g _8o _8s lfloat _ohe" aria-hidden="true" tabindex="-1" target="" data-ft="{"tn":"\\u003C"}" href="https://www.facebook.com/LifeFunny2017/?ref=nf&hc_ref=ARTJaohAvwH27C20j3tc3ZZond6X8R6xZVnVPxGgNU4VHsXJNh7uyuOzkr6uSVpdCGU&__xts__%5B0%5D=68.ARCP4iaPZCXXlj82BZeKavKaCzMBLqfy-JdzZ6T4W32oIcSADXPga5nPWCXupfaWHM_QPpm1flAKzM7W1OPqnjMYsuk6SlPbiJZK_8NpH6A5tUwuLBpZq8iKZn39-V3pAuVuFBNpdBTjndGd_PakKVsUao1J_CsWzDrClWaSqpX55efNnC3ScrCIo_kZus5hjtJHTVJnEPjyq5HCPhZ9VY2zvRQ7VID50ct5Z4Vv83G6rYj4FpV3rR55vHm7XqDyUGEfUGSwjPF1MjltKPppWtPDuGTSpSTMZaUJ6fi1SlLBO9Ep4g3geicYk4GOhnAgVlGqudAfjfAtf5pz&__tn__=%3C-R"><div class="_38vo"><div><img class="_s0 _4ooo _5xib _5sq7 _44ma _rw img" src="https://scontent.ffln4-1.fna.fbcdn.net/v/t1.0-1/p50x50/17021623_1866091533667009_7165204595070033638_n.png?_nc_cat=1&_nc_ht=scontent.ffln4-1.fna&oh=9a98f7b2ecf6f84df98e23780051972d&oe=5CF79B10" alt="" aria-label="Life Funny" role="img" /></div></div></a><div class="clearfix _42ef"><div class="rfloat _ohf"></div><div class="u_c3pyo2ta4"><div><div class="_6a _5u5j"><div class="_6a _6b" style="height:40px"></div><div class="_6a _5u5j _6b"><h5 class="_14f3 _14f5 _5pbw _5vra" data-ft="{"tn":"C"}"><span class="fwn fcg"><span class="fwb fcg" data-ft="{"tn":"k"}"><a href="https://www.facebook.com/LifeFunny2017/?hc_ref=ARSWPY47XH7nQ-sao5sqWBMX8H1myzQXleTfZCGPRbE851HXxZuM0Y8dShQhJrLr6IA&fref=nf&__xts__%5B0%5D=68.ARCP4iaPZCXXlj82BZeKavKaCzMBLqfy-JdzZ6T4W32oIcSADXPga5nPWCXupfaWHM_QPpm1flAKzM7W1OPqnjMYsuk6SlPbiJZK_8NpH6A5tUwuLBpZq8iKZn39-V3pAuVuFBNpdBTjndGd_PakKVsUao1J_CsWzDrClWaSqpX55efNnC3ScrCIo_kZus5hjtJHTVJnEPjyq5HCPhZ9VY2zvRQ7VID50ct5Z4Vv83G6rYj4FpV3rR55vHm7XqDyUGEfUGSwjPF1MjltKPppWtPDuGTSpSTMZaUJ6fi1SlLBO9Ep4g3geicYk4GOhnAgVlGqudAfjfAtf5pz&__tn__=kC-R">Life Funny<a href="https://www.facebook.com/LifeFunny2017/?hc_ref=ARSWPY47XH7nQ-sao5sqWBMX8H1myzQXleTfZCGPRbE851HXxZuM0Y8dShQhJrLr6IA&fref=nf&__xts__%5B0%5D=68.ARCP4iaPZCXXlj82BZeKavKaCzMBLqfy-JdzZ6T4W32oIcSADXPga5nPWCXupfaWHM_QPpm1flAKzM7W1OPqnjMYsuk6SlPbiJZK_8NpH6A5tUwuLBpZq8iKZn39-V3pAuVuFBNpdBTjndGd_PakKVsUao1J_CsWzDrClWaSqpX55efNnC3ScrCIo_kZus5hjtJHTVJnEPjyq5HCPhZ9VY2zvRQ7VID50ct5Z4Vv83G6rYj4FpV3rR55vHm7XqDyUGEfUGSwjPF1MjltKPppWtPDuGTSpSTMZaUJ6fi1SlLBO9Ep4g3geicYk4GOhnAgVlGqudAfjfAtf5pz&__tn__=kC-R"></a></a></span></span></h5><div class="_5pcp _5lel _2jyu _232_" id="feed_subtitle_2562021150480797:9:0" data-testid="story-subtitle"><span class="z_c3pyo1brp"><span class="fsm fwn fcg"><a href="/LifeFunny2017/videos/2562021150480797/?__xts__%5B0%5D=68.ARCP4iaPZCXXlj82BZeKavKaCzMBLqfy-JdzZ6T4W32oIcSADXPga5nPWCXupfaWHM_QPpm1flAKzM7W1OPqnjMYsuk6SlPbiJZK_8NpH6A5tUwuLBpZq8iKZn39-V3pAuVuFBNpdBTjndGd_PakKVsUao1J_CsWzDrClWaSqpX55efNnC3ScrCIo_kZus5hjtJHTVJnEPjyq5HCPhZ9VY2zvRQ7VID50ct5Z4Vv83G6rYj4FpV3rR55vHm7XqDyUGEfUGSwjPF1MjltKPppWtPDuGTSpSTMZaUJ6fi1SlLBO9Ep4g3geicYk4GOhnAgVlGqudAfjfAtf5pz&__tn__=-R" aria-label="Video, Hahaha 😂😂😂perfect 😳👏👏👏, Duration: 16 seconds" ajaxify="/LifeFunny2017/videos/vb.1837955386480624/2562021150480797/?type=3&source=12&__xts__%5B0%5D=68.ARCP4iaPZCXXlj82BZeKavKaCzMBLqfy-JdzZ6T4W32oIcSADXPga5nPWCXupfaWHM_QPpm1flAKzM7W1OPqnjMYsuk6SlPbiJZK_8NpH6A5tUwuLBpZq8iKZn39-V3pAuVuFBNpdBTjndGd_PakKVsUao1J_CsWzDrClWaSqpX55efNnC3ScrCIo_kZus5hjtJHTVJnEPjyq5HCPhZ9VY2zvRQ7VID50ct5Z4Vv83G6rYj4FpV3rR55vHm7XqDyUGEfUGSwjPF1MjltKPppWtPDuGTSpSTMZaUJ6fi1SlLBO9Ep4g3geicYk4GOhnAgVlGqudAfjfAtf5pz&__tn__=-R" rel="theater" class="_5pcq" target=""><abbr title="12/18/18, 7:49 AM" data-utime="1545148149" data-shorten="1" class="_5ptz"><span class="timestampContent">December 18, 2018</span></abbr></a></span></span><span class="_6spk" role="presentation" aria-hidden="true"> · </span><a class="uiStreamPrivacy inlineBlock fbStreamPrivacy fbPrivacyAudienceIndicator _5pcq" aria-label="Public" href="#" role="button" data-hover="tooltip" data-tooltip-content="Public"><i class="lock img sp_IhYF_V8nmKn sx_b29f71"></i></a></div></div></div></div></div></div></div></div><div class="_5pbx userContent _3576" data-ft="{"tn":"K"}"><p>Hahaha <span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/td0/1/16/1f602.png")"></span></span><span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/td0/1/16/1f602.png")"></span></span><span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/td0/1/16/1f602.png")"></span></span>perfect <span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/t2e/1/16/1f633.png")"></span></span><span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/tfe/1/16/1f44f.png")"></span></span><span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/tfe/1/16/1f44f.png")"></span></span><span class="_5mfr"><span class="_6qdm" style="height: 16px; width: 16px; font-size: 16px; background-image: url("https://static.xx.fbcdn.net/images/emoji.php/v9/tfe/1/16/1f44f.png")"></span></span></p></div><div class="_3x-2" data-ft="{"tn":"H"}"><div data-ft="{"tn":"H"}"></div></div><div></div></div></div><div><form rel="async" class="commentable_item collapsed_comments" method="post" data-ft="{"tn":"]"}" action="/ajax/ufi/modify.php" onsubmit="" id="u_0_16"><input type="hidden" name="jazoest" value="2665" autocomplete="off" /><input type="hidden" name="lsd" value="AVrTIt0O" autocomplete="off" /><input type="hidden" autocomplete="off" name="ft_ent_identifier" value="2270989333177225" /><input type="hidden" autocomplete="off" name="data_only_response" value="1" /><div class="_sa_ _gsd _fgm _5vsi _192z"><div class="_1t6k"><span class="fcg">433K Views</span></div><div class="_37uu"></div></div><div class="uiUfi UFIContainer _3-a6 _4eno _1blz _69ad _65_9 _5pc9 _5vsj _5v9k" id="u_0_15"></div></form></div></div></div></div></div></div> --></code></div>
答案 0 :(得分:0)
需要获取注释部分的节点://code/node()
,将接收到的值转换为可在其中找到所需节点的DOM对象。
JavaScript示例:
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
let subDocumentXpath= "//code/node()"; // set xpath of your subdocument
let subDocumentSearchElementTagName = "div"; // set tag of your element
let subDocumentString = getElementByXpath(subDocumentXpath);
let documentCustom = new DOMParser().parseFromString(subDocumentString, "text/xml");
let documentCustomGetElement = documentCustom.getElementsByTagName(subDocumentSearchElementTagName)[0].childNodes; // your element here