{"id":860,"date":"2024-11-07T14:48:48","date_gmt":"2024-11-07T06:48:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/860\/"},"modified":"2024-11-07T14:48:48","modified_gmt":"2024-11-07T06:48:48","slug":"colly-%e8%84%9a%e6%9c%ac%e6%8a%a5%e9%94%99%ef%bc%9a%e5%87%ba%e7%8e%b0invalid-memory-address-or-nil-pointer-dereference%e9%94%99%e8%af%af%ef%bc%8c%e8%af%a5%e5%a6%82%e4%bd%95%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/860\/","title":{"rendered":"Colly \u811a\u672c\u62a5\u9519\uff1a\u51fa\u73b0\u201cinvalid memory address or nil pointer dereference\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1053\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173017442771331.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173017442771331.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173017442771331-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173017442771331-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173017442771331-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Colly \u811a\u672c\u62a5\u9519\uff1a\u51fa\u73b0\u201cinvalid memory address or nil pointer dereference\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Colly \u811a\u672c\u62a5\u9519\uff1a\u51fa\u73b0\u201cinvalid memory address or nil pointer dereference\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>colly \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef<\/strong><\/p>\n<p>\u5728\u64b0\u5199 colly \u7684\u793a\u4f8b\u811a\u672c\u65f6\uff0c\u4f60\u9047\u5230\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u5bfc\u81f4\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n<p>\u201cpanic: runtime error: invalid memory address or nil pointer dereference\u201d<\/p>\n<p>\u5177\u4f53\u9519\u8bef\u51fa\u73b0\u5728 colly.go \u6587\u4ef6\u7684\u7b2c 55 \u884c\uff0c\u5f52\u56e0\u4e8e\u7a7a\u6307\u9488\u5f15\u7528\u3002\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u4ed4\u7ec6\u68c0\u67e5\u7b2c 55 \u884c\uff0c\u786e\u4fdd\u4efb\u4f55\u6307\u9488\u5f15\u7528\u5747\u975e nil\u3002<\/p>\n<pre>func main() {\n    c := colly.NewCollector()\n    c.OnHTML(\"img[src]\", downloadImages)\n    c.Visit(\"https:\/\/example.com\")\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fColly \u811a\u672c\u62a5\u9519\uff1a\u51fa\u73b0\u201cinvalid memory address or nil pointer dereference\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>colly \u51fa\u73b0 \u201cinvalid memory address or nil pointer dereference\u201d \u9519\u8bef \u5728\u64b0\u5199 colly \u7684\u793a\u4f8b\u811a\u672c\u65f6\uff0c\u4f60\u9047\u5230\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u5bfc\u81f4\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef\u4fe1\u606f\uff1a \u201cpanic: runtime error: invalid memory address or nil pointer dereference\u201d \u5177\u4f53\u9519\u8bef\u51fa\u73b0\u5728 colly.go \u6587\u4ef6\u7684\u7b2c 55 \u884c\uff0c\u5f52\u56e0\u4e8e\u7a7a\u6307\u9488\u5f15\u7528\u3002\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u4ed4\u7ec6\u68c0\u67e5\u7b2c 55 \u884c\uff0c\u786e\u4fdd\u4efb\u4f55\u6307\u9488\u5f15\u7528\u5747\u975e nil\u3002 func main() { c := colly.NewCollector() c.OnHTML(&#8220;img[src]&#8221;, downloadImages) c.Visit(&#8220;https:\/\/example.com&#8221;) } \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662fColly \u811a\u672c\u62a5\u9519\uff1a\u51fa\u73b0\u201cinvalid memory address or nil pointer dereference\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-860","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=860"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/860\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}