首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么页面不返回任何xpath?

为什么页面不返回任何xpath?
EN

Stack Overflow用户
提问于 2018-09-28 23:01:12
回答 1查看 43关注 0票数 1

我遇到过一些互联网页面,当我运行xpath查询(在两个不同的xpath检查器chrome扩展中工作)时,它们不会在我运行它们的PHP页面上返回。我想知道这些页面是否有某种类型的xpath拦截器或其他东西(是的,我正在检查他们的robots.txt是否允许)。或者其他的伏都教?感谢您能提供的任何帮助!

下面是我的代码中的两行(编辑后添加更多):

代码语言:javascript
运行
复制
    $c = curl_init($url);
    curl_setopt($c, CURLOPT_HEADER, false);
    curl_setopt($c, CURLOPT_USERAGENT, $this->getUserAgent());
    curl_setopt($c, CURLOPT_FAILONERROR, true);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_AUTOREFERER, true);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_TIMEOUT, 10);

    // Grab the data.
    $html = curl_exec($c);
    curl_close($c);
$dom = new DOMDocument();
@$dom->loadHtml($html);
$xpath = new DOMXPath($dom);

$jsonScripts = $xpath->query('//script[@type="application/ld+json"]');
if($TEST){echo "there are " . $jsonScripts->length . " JSONs<br>";}

从一个不会返回任何内容的互联网页面

代码语言:javascript
运行
复制
<script type="application/ld+json">{"@context":"http:\/\/schema.org\/","@type":"Recipe","name":"Healthy Garlic Scallops Recipe","author":{"@type":"Person","name":"Florentina"},"datePublished":"2015-07-29T22:39:18+00:00","description":"Italian garlic scallops, seared to a golden perfection in a cast iron pan and cooked in healthy clarified butter for the ultimate seafood meal!","image":["https:\/\/ciaoflorentina.com\/wp-content\/uploads\/2015\/07\/Garlic-Scallops-Healthy-4.jpg"],"recipeYield":"2","prepTime":"PT5M","cookTime":"PT5M","totalTime":"PT10M","recipeIngredient":["1 lb large scallops","1\/4 c clarified butter ghee","5 cloves garlic (grated)","1  large lemon (zested)","1\/4 c Italian parsley (roughly chopped)","1\/2 tsp sea salt + more to taste","1\/4 tsp peppercorn medley (freshly ground)","1\/4 tsp red pepper flakes","A pinch of sweet paprika","1 tsp extra virgin olive oil"],"recipeInstructions":[{"@type":"HowToStep","text":"Make sure to pat dry the scallops on paper towels very well before cooking."},{"@type":"HowToStep","text":"Heat up a large cast iron skillet on medium flame."},{"@type":"HowToStep","text":"Meanwhile in a medium bowl toss the scallops with a drizzle of olive oil or butter ghee, just enough to coat it all over. Sprinkle them with the sea salt, cracked pepper, red pepper flakes and sweet paprika. Toss to coat gently."},{"@type":"HowToStep","text":"Add a little drizzle of butter ghee to the hot skillet, just enough to coat the bottom. Add the scallops making sure not to overcrowd the pan, and sear for about 2 minutes on each side until nicely golden. ( Use a small spatula to flip them over individually )"},{"@type":"HowToStep","text":"Add the butter ghee to the skillet with the scallops and then add the garlic. Remove from heat and using a spatula push the garlic around to infuse the sauce for about 30 seconds. The heat from the skillet will be enough for the garlic to work its magic into the butter. This is how you avoid that pungent burnt garlicky taste we don\u2019t like."},{"@type":"HowToStep","text":"We are just looking to extract all that sweetness from the garlic, and this is how you do it, without burning."},{"@type":"HowToStep","text":"Squeeze half of the lemon all over the scallops and move the skillet around a little so it combines with the butter. Sprinkle with the minced parsley, lemon zest and a drizzle of extra virgin olive oil. Serve with crusty bread or al dente capellini noodles."}],"recipeCategory":["Main Dishes"],"recipeCuisine":["Italian"],"aggregateRating":{"@type":"AggregateRating","ratingValue":"5","ratingCount":"8"}}</script>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52558033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档