const axios = require('axios')
const xpath = require("xpath-html")
const getWallData = async(domain) => {
try {
const respose = await axios.get(`https://m.vk.com/${domain}`)
const node = xpath
.fromPageSource(respose.data)
.findElements('//a[@class="wi_date"]')
console.log(node[0].toString())
} catch (error) {
console.error(error)
}
}
getWallData('club38463533')
Вывод:
<a class="wi_date" href="/wall-38463533_1314" rel="noopener" xmlns="http://www.w3.org/1999/xhtml">вчера в 14:53</a>
Но если сделаю:
//a[@class="wi_date"]/@href
То сразу
Error: Unexpected character :
at XPathParser.tokenize (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/node_modules/xpath/xpath.js:1214:9)
at XPathParser.parse (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/node_modules/xpath/xpath.js:1228:17)
at new XPathExpression (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/node_modules/xpath/xpath.js:4287:17)
at Object.exports.selectWithResolver (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/node_modules/xpath/xpath.js:4735:19)
at XPath.<anonymous> (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/node_modules/xpath/xpath.js:4730:18)
at XPath.findElements (/home/tony/Разработка/telegram-bot/node_modules/xpath-html/src/XPath.js:48:24)
at getWallData (/home/tony/Разработка/telegram-bot/src/index.js:9:14)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
И я окончательно запутался