我正在使用名為php-spider的精彩腳本,目的是從一些網站上抓取標題、描述、H1、H2、H3 和 H4。作為配置腳本的一部分,有必要設置一個“XpathExpressionDiscoverer”來指示腳本如何在每個頁面上找到額外的超鏈接以進行抓取。我假設這是指標準的 Xpath 查詢語言。我的目標是找到一個通常適用于大多數網站的 XpathExpressionDiscoverer(而不是要求我為每個站點自定義它)。這是我嘗試過的:我注意到作者提供的示例使用非常具體的 XpathExpressionDiscoverer 來抓取給定的示例站點:// The URI we want to start crawling with$seed = 'http://dmoztools.net/Computers/Internet/';// We add an URI discoverer. Without it, the spider wouldn't get past the seed resource.$spider->getDiscovererSet()->set(new XPathExpressionDiscoverer("//*[@id='cat-list-content-2']/div/a"));由于我的目標只是發現頁面上的任何超鏈接,因此我嘗試將 XPath 擴展為更通用的內容(“//a”),如下所示:// We add an URI discoverer. Without it, the spider wouldn't get past the seed resource.$spider->getDiscovererSet()->set(new XPathExpressionDiscoverer("//a"));雖然這個新的 Xpath 成功地抓取了示例站點 (dmoztools.net),但它似乎不適用于我嘗試的其他示例(如下)。它只是抓取種子頁面,但無法發現或抓取頁面上的其他 URI(即使它們具有應與 Xpath 匹配的 A HREF 標記)。示例 A:https ://www.petco.com/shop/en/petcostore/category/fish示例 B:https ://www.thetruthaboutcars.com/你碰巧看到我要去哪里錯了嗎?謝謝!
使用 php-spider,是否有一個標準的 Xpath 可以發現大多數網站上的 URI?
慕婉清6462132
2022-12-23 13:18:30