php - 如何从 url 获取信息
问题描述
有没有办法通过链接(标题、副标题、详细信息、图片)获取链接信息?
就像电报或 LinkedIn 中的电报和 LinkedIn 一样,当您将一些链接用于发布或发送到频道或群组时,您可以看到该链接的一些详细信息。
我该如何为 php 代码执行此操作?
解决方案
获取有关该链接的信息的唯一方法是爬取页面,然后从<meta property="og:..."
标题中的特殊元标记 ( ) 中提取数据,然后相应地显示它。也许你需要一个现成的包可以做到这一点,或者即使使用 jQuery 你也应该能够解析它。以下是当前页面生成的标签示例:
<meta property="og:type" content="website">
<meta property="og:url" content="https://stackoverflow.com/questions/58146161/ability-to-get-article-link-information/58146431">
<meta property="og:site_name" content="Stack Overflow">
<meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded">
<meta name="twitter:card" content="summary">
<meta name="twitter:domain" content="stackoverflow.com">
<meta name="twitter:title" property="og:title" itemprop="name" content="Ability to get article link information">
<meta name="twitter:description" property="og:description" itemprop="description" content="The only way to get information about that link is to crawl the page and then extract the data from special meta tags (&lt;meta property="og:...") in the header, then display it accordingly. Perha...">
<meta name="twitter:app:country" content="US">
<meta name="twitter:app:name:iphone" content="Stack Exchange iOS">
<meta name="twitter:app:id:iphone" content="871299723">
<meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/58146161/ability-to-get-article-link-information/58146431">
<meta name="twitter:app:name:ipad" content="Stack Exchange iOS">
<meta name="twitter:app:id:ipad" content="871299723">
<meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/58146161/ability-to-get-article-link-information/58146431">
<meta name="twitter:app:name:googleplay" content="Stack Exchange Android">
<meta name="twitter:app:url:googleplay" content="http://stackoverflow.com/questions/58146161/ability-to-get-article-link-information/58146431">
<meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin">
推荐阅读
- python - 使用 API 抓取所有公司的完整信息,python 中的请求
- laravel - “--timeout”选项不存在
- php - 无法连接到数据库但数据库没有错误
- node.js - 如何强大的保存图像?
- python - 根据模型向表格中的单元格添加值
- python - Django ModelForm 没有获取实例数据
- python - 如何在 tensorflow 中的 GCN LSTM 中进行序列到序列预测
- python - 为什么我不能概括这个功能?
- spring-boot - 将 java 系统属性添加到使用 buildback 创建的 Spring Boot 映像中
- php - 将 2 个 foreach 循环合并为一个具有不同逻辑的循环