{"id":17246210,"url":"https://github.com/hanson/weibot","last_synced_at":"2025-04-06T04:14:34.902Z","repository":{"id":36291085,"uuid":"223108404","full_name":"Hanson/weibot","owner":"Hanson","description":"微博爬虫，模拟登录，数据抓取","archived":false,"fork":false,"pushed_at":"2023-04-19T21:14:39.000Z","size":91,"stargazers_count":235,"open_issues_count":4,"forks_count":24,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T03:07:02.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hanson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-11-21T06:54:22.000Z","updated_at":"2024-12-02T11:48:34.000Z","dependencies_parsed_at":"2024-01-15T13:35:27.782Z","dependency_job_id":null,"html_url":"https://github.com/Hanson/weibot","commit_stats":{"total_commits":11,"total_committers":3,"mean_commits":"3.6666666666666665","dds":0.4545454545454546,"last_synced_commit":"8af7e27b37a3cf7b30c0ad2d54347f00412bb30e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hanson%2Fweibot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hanson%2Fweibot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hanson%2Fweibot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hanson%2Fweibot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hanson","download_url":"https://codeload.github.com/Hanson/weibot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430963,"owners_count":20937875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T06:32:43.710Z","updated_at":"2025-04-06T04:14:34.885Z","avatar_url":"https://github.com/Hanson.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# weibot\n\n微博机器人\n\n## 安装\n\n`composer require hanson/weibot:dev-master -vvv`\n\n## 文档\n\n### 登录\n\n```php\n\u003c?php\n\ninclude_once __DIR__.'/../vendor/autoload.php';\n\n$weibo = new \\Hanson\\Weibot\\Weibot([\n    'username' =\u003e '',\n    'password' =\u003e '',\n    'cookie_path' =\u003e __DIR__.'/cookie', // cookie 存储路径\n    'debug' =\u003e []\n]);\n```\n\n### 搜索 Search\n\n```php\n\u003c?php\n$search = $weibo-\u003esearch;\n\n$search-\u003egetData([\n    'keyword' =\u003e '关键词',\n//     'page' =\u003e 1, // 页数\n//    'start_at' =\u003e '2019-11-07-6', # yyyy-mm-dd-h 时间筛选\n//    'end_at' =\u003e '2019-12-07-8',\n]);\n```\n\n### 我的关注 Follow\n\n```php\n\u003c?php\n$follow = $weibo-\u003efollow;\n\n// 获取我的关注\n$follow-\u003egetData([\n//     'page' =\u003e 1, // 页数\n]);\n\n// 取消关注 \n$follow-\u003eunfollow($uid);\n```\n\n### 微博 Post\n\n```php\n\u003c?php\n$post = $weibo-\u003epost;\n\n/**\n * 发送微博\n *\n * @param string $text 发送的微博内容\n * @return mixed\n */\n$post-\u003esend($text);\n\n/**\n * 评论微博\n *\n * @param $mid string 微博 id\n * @param $content string 评论内容\n * @param bool $forward 是否转发\n * @return mixed\n */\n$post-\u003ecomment($mid, $content, $forward = false)\n\n/**\n * 转发微博\n *\n * @param $mid\n * @param $reason string 转发内容\n * @param bool $isComment 是否评论\n * @param bool $isCommentBase 是否对原微博评论\n * @return mixed\n */\n$post-\u003eforward($mid, $reason, $isComment = false, $isCommentBase = false)\n\n/**\n * 删除微博\n * \n * @param $mid string 微博id\n * @return false|string\n */\n$post-\u003edelete($mid)\n\n// 我的微博（待开发）\n$post-\u003egetData()\n```\n\n## 参与开发更多 API\n\n基于 weibot，开发微博的抓包工作会更加简单\n\n### 一、登录\n\n微博很多操作都需要登录，所以写脚本的时候先登录，让 cookie 存储起来 `$weibo-\u003elogin()`\n\n### 二、抓包\n\n根据浏览器看到的请求，我们可以尝试模拟一下\n\n```php\n\u003c?php\n// $client 已经是一个带 cookie 的“浏览器”客户端了，根据实际情况进行 get 或者 post\n$client = \\Hanson\\Weibot\\Api\\Api::getClient();\n\n$response = $client-\u003epost('http://weibo.com', [\n    'header' =\u003e [\n        // 如果有特殊 header 需求    \n    ],\n    'form_params' =\u003e [\n        // 各种请求参数\n    ]\n]);\n\n// 得到的 response 有可能是页面，也有可能是接口，自行处理\n$data = json_decode($response-\u003egetBody()-\u003egetContents(), true);\n```\n\n### 相关头绪\n\n* 微博部分页面是基于页面渲染的模式\n* 微博的渲染并不按套路出牌，而是使用了 FM.view 的内部框架\n* 抓取内容需要先在 script 里正则匹配出来相关的 HTML。 例如：`preg_match_all('/Pl_Official_MyProfileFeed__20.*html\\\":\\\"(.*)\\\"}/', $html, $matches);`\n* 有部分地方是异步接口的，例如下滑滚动分页\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanson%2Fweibot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanson%2Fweibot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanson%2Fweibot/lists"}