Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherrio is unable to retrieve content with property of og in the meta tag #3542

Open
luoriwusheng-xia opened this issue Dec 12, 2023 · 3 comments

Comments

@luoriwusheng-xia
Copy link

base example

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta property="og:title" content="预览标题">
  <meta property="og:description" content="预览描述">
  <meta property="og:image:width" content="40">
  <meta property="og:image:height" content="80">
  <meta property="og:image" content="http://xxxsasd.png">
  <meta property="og:url" content="链接的URL">
</head>

<body>
  <div>test web site</div>
</body>

</html>

use live-server start a local web site

nodejs code

import { load } from 'cheerio'

const fetchTargetText = (url: string): Promise<string> => {
	return new Promise((resolve, reject) => {
		fetch(url)
			.then((r) => r.text())
			.then((res) => {
				resolve(res)
			})
			.catch((e) => {
				reject(e)
			})
	})
}

const const resolveText = (text: string) => {
    const $ = load(text)
    let t = $('meta')
    
    let aa =$('meta[property="og:"]')
    
    console.log(t);
    
  // ? The length of the content obtained here is 0
    console.log(aa);
}


const run = async() => {
  
  let text = await fetchTargetText(url)
  
  return resolveText(text)
}


run ()
@luoriwusheng-xia
Copy link
Author

image

@fb55
Copy link
Member

fb55 commented Dec 14, 2023

Try [property^="og:"]. You are currently looking for an exact match, where there are none.

@luoriwusheng-xia
Copy link
Author

Try [property^="og:"]. You are currently looking for an exact match, where there are none.

Still not working

node: v20.10.0
 "cheerio": "1.0.0-rc.12"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants