{"id":22235,"date":"2024-10-29T15:03:19","date_gmt":"2024-10-29T07:03:19","guid":{"rendered":"https:\/\/123proxy.cn\/blogs\/2024\/10\/scrapy-socks5%e4%bb%a3%e7%90%86%e9%85%8d%e7%bd%ae%ef%bc%9a%e8%af%a6%e8%a7%a3%e6%ad%a5%e9%aa%a4%e4%b8%8e%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81\/"},"modified":"2024-10-29T15:03:19","modified_gmt":"2024-10-29T07:03:19","slug":"scrapy-socks5%e4%bb%a3%e7%90%86%e9%85%8d%e7%bd%ae%ef%bc%9a%e8%af%a6%e8%a7%a3%e6%ad%a5%e9%aa%a4%e4%b8%8e%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/123proxy.cn\/blogs\/2024\/10\/scrapy-socks5%e4%bb%a3%e7%90%86%e9%85%8d%e7%bd%ae%ef%bc%9a%e8%af%a6%e8%a7%a3%e6%ad%a5%e9%aa%a4%e4%b8%8e%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81\/","title":{"rendered":"Scrapy SOCKS5\u4ee3\u7406\u914d\u7f6e\uff1a\u8be6\u89e3\u6b65\u9aa4\u4e0e\u793a\u4f8b\u4ee3\u7801"},"content":{"rendered":"<p>\u5728\u5982\u4eca\u8fd9\u4e2a\u6570\u636e\u9a71\u52a8\u7684\u65f6\u4ee3\uff0c<strong>\u7f51\u7edc\u6293\u53d6<\/strong>\u6210\u4e3a\u4f01\u4e1a\u83b7\u53d6\u7ade\u4e89\u4f18\u52bf\u7684\u5173\u952e\u624b\u6bb5\u4e4b\u4e00\u3002\u7136\u800c\uff0c\u5982\u4f55\u6709\u6548\u96c6\u6210<code>SOCKS5\u4ee3\u7406<\/code>\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u6570\u636e\u91c7\u96c6\uff0c\u5374\u8ba9\u8bb8\u591a\u5f00\u53d1\u8005\u611f\u5230\u56f0\u6270\u3002\u5c24\u5176\u662f\u5728\u4f7f\u7528\u9886\u5148\u7684\u6293\u53d6\u6846\u67b6<strong>Scrapy<\/strong>\u65f6\uff0c\u5176\u67b6\u6784\u5bf9<strong>SOCKS5<\/strong>\u4ee3\u7406\u7684\u652f\u6301\u6709\u9650\uff0c\u8fd9\u5e38\u5e38\u963b\u788d\u5f00\u53d1\u4eba\u5458\u6700\u5927\u5316\u5730\u5229\u7528\u4ee3\u7406\u6240\u5e26\u6765\u7684\u4f18\u52bf\u3002<\/p>\n<p>\u8fd9\u4e00\u6311\u6218\u65e9\u57282014\u5e74\u7684GitHub\u95ee\u9898\u8ba8\u8bba\uff08\u5982<strong>issue #747<\/strong>\uff09\u4e2d\u88ab\u63d0\u53ca\uff0c\u7136\u800c\u81f3\u4eca\u4ecd\u7136\u7f3a\u4e4f<code>\u539f\u751f\u652f\u6301<\/code>\u3002\u5728\u4f17\u591a\u7684\u793e\u533a\u8d44\u6e90\u4e2d\uff0c\u65b9\u6cd5\u7684\u7e41\u6742\u548c\u5de5\u5177\u7684\u591a\u6837\u6027\u4e5f\u8ba9\u4eba\u65e0\u4ece\u4e0b\u624b\uff0c\u800cDocker\u7b49<code>\u9ad8\u7ea7\u8def\u7531<\/code>\u6280\u672f\u6210\u4e3a\u4e86\u8ba8\u8bba\u70ed\u70b9\u3002\u5c3d\u7ba1\u6709\u8bb8\u591a\u6280\u672f\u535a\u5ba2\u548c\u6307\u5bfc\u6587\u7ae0\u63d0\u4f9b\u4e86\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u5f88\u591a\u65f6\u5019\u90fd\u6ca1\u80fd\u6df1\u5165\u6d45\u51fa\u5730\u5448\u73b0\u51fa\u660e\u786e\u7684\u64cd\u4f5c\u6b65\u9aa4\u548c\u793a\u4f8b\u3002<\/p>\n<p>\u672c\u6587\u5c06\u8be6\u5c3d\u4ecb\u7ecd\u5982\u4f55\u5728Scrapy\u4e2d\u914d\u7f6eSOCKS5\u4ee3\u7406\u3002\u4ece<code>\u73af\u5883\u51c6\u5907<\/code>\u5230<code>\u5b9e\u9645\u914d\u7f6e<\/code>\uff0c\u4ece<code>\u6027\u80fd\u4f18\u5316<\/code>\u5230<code>\u9879\u76ee\u5e94\u7528<\/code>\uff0c\u5c06\u4e3a\u8bfb\u8005\u63d0\u4f9b\u4e00\u5957\u7cfb\u7edf\u5316\u7684\u6307\u5357\uff0c\u4ee5\u5b9e\u73b0\u5168\u65b9\u4f4d\u7684<code>SOCKS5<\/code>\u4ee3\u7406\u6574\u5408\u3002\u65e0\u8bba\u662f\u5bf9\u6297IP\u5c01\u7981\uff0c\u8fd8\u662f\u63d0\u5347<code>\u6293\u53d6\u6548\u7387<\/code>\uff0c\u8fd9\u4e00\u7bc7\u6587\u7ae0\u90fd\u5c06\u5728\u63a2\u7d22\u7f51\u7edc\u6293\u53d6\u7684\u5f81\u9014\u4e2d\u4e3a\u4f60\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002<\/p>\n<h2>Key Takeaways<\/h2>\n<ul>\n<li>Scrapy is a powerful web scraping framework but lacks native support for SOCKS5 proxies, requiring advanced integration techniques.<\/li>\n<li>Understanding the differences between HTTP and SOCKS5 proxies can help developers choose the appropriate proxy type for web scraping tasks.<\/li>\n<li>Common methods for integrating SOCKS5 with Scrapy include utilizing meta parameters and custom middleware, which enhance proxy handling and performance.<\/li>\n<li>Community resources such as GitHub discussions and tech tutorials provide valuable insights and solutions for integrating SOCKS5 proxies effectively.<\/li>\n<li>By leveraging services like 123Proxy, developers can access superior proxy solutions to meet data scraping requirements and improve user privacy.<\/li>\n<li>Optimizing Scrapy&#8217;s performance with SOCKS5 involves employing techniques like load balancing and error handling strategies to enhance success rates in data retrieval.<\/li>\n<\/ul>\n<h2>SOCKS5\u4ee3\u7406\u7b80\u4ecb\u4e0e\u4f18\u52bf<\/h2>\n<h3>SOCKS5\u4ee3\u7406\u7684\u57fa\u672c\u6982\u5ff5<\/h3>\n<p><strong>SOCKS5\u4ee3\u7406<\/strong>\u662f\u4e00\u79cd\u7f51\u7edc\u534f\u8bae\uff0c\u7528\u4e8e\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u8f6c\u53d1\u7f51\u7edc\u6d41\u91cf\u3002\u5176\u4e3b\u8981\u529f\u80fd\u662f\u5145\u5f53\u5ba2\u6237\u7aef\u4e0e\u76ee\u6807\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u4e2d\u4ecb\uff0c\u4fc3\u8fdb\u6570\u636e\u7684\u4f20\u8f93\uff0c\u4f7f\u5f97\u7528\u6237\u80fd\u591f\u9690\u85cf\u5176\u771f\u5b9e\u7684IP\u5730\u5740\uff0c\u63d0\u5347\u7f51\u7edc\u5b89\u5168\u6027\u3002\u4e0e\u4f20\u7edf\u7684HTTP\u4ee3\u7406\u76f8\u6bd4\uff0cSOCKS5\u4ee3\u7406\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u79cd\u7c7b\u7684\u6d41\u91cf\uff0c\u9664\u4e86HTTP\uff0c\u8fd8\u80fd\u591f\u5904\u7406FTP\u3001SMTP\u7b49\u591a\u79cd\u534f\u8bae\u3002\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u5176\u5728\u591a\u79cd\u5e94\u7528\u573a\u666f\u4e2d\uff0c\u5c24\u5176\u662f\u6570\u636e\u6293\u53d6\u65b9\u9762\uff0c\u5c55\u73b0\u4e86\u5de8\u5927\u7684\u6f5c\u529b\u3002<\/p>\n<p>SOCKS5\u4ee3\u7406\u4f7f\u7528\u8f83\u5c11\u7684\u8d44\u6e90\uff0c\u80fd\u591f\u5728\u9ad8\u5ef6\u8fdf\u548c\u4f4e\u5e26\u5bbd\u7684\u73af\u5883\u4e2d\u6709\u6548\u5de5\u4f5c\u3002\u8fd9\u4e00\u4f18\u70b9\u4f7f\u5f97\u7528\u6237\u5728\u4e00\u5b9a\u6761\u4ef6\u4e0b\u53ef\u4ee5\u4eab\u53d7\u66f4\u6d41\u7545\u7684\u7f51\u7edc\u4f53\u9a8c\uff0c\u7279\u522b\u662f\u5728\u8fdb\u884c\u9891\u7e41\u7684\u7f51\u9875\u6293\u53d6\u65f6\uff0c\u80fd\u591f\u6709\u6548\u51cf\u5c11\u7531\u4e8e\u7f51\u7edc\u5ef6\u8fdf\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<h3>HTTP\u4ee3\u7406\u4e0eSOCKS5\u4ee3\u7406\u7684\u533a\u522b<\/h3>\n<p>\u5728\u4e86\u89e3<strong>SOCKS5\u4ee3\u7406<\/strong>\u7684\u57fa\u672c\u6982\u5ff5\u540e\uff0c\u6bd4\u8f83\u5176\u4e0e<strong>HTTP\u4ee3\u7406<\/strong>\u7684\u533a\u522b\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002HTTP\u4ee3\u7406\u4ec5\u80fd\u5904\u7406HTTP\u548cHTTPS\u6d41\u91cf\uff0c\u7b80\u5355\u6765\u8bf4\uff0c\u5b83\u53ea\u80fd\u7528\u4e8e\u7f51\u9875\u6d4f\u89c8\u548c\u57fa\u672c\u7684\u7f51\u7edc\u8bf7\u6c42\u3002\u800cSOCKS5\u4ee3\u7406\u5219\u4e0d\u540c\uff0c\u5b83\u652f\u6301\u66f4\u591a\u7684\u534f\u8bae\uff0c\u80fd\u5904\u7406\u4efb\u4f55\u4f20\u8f93\u5c42\u6570\u636e\uff0c\u8fd9\u4f7f\u5f97\u5b83\u80fd\u591f\u6267\u884c\u66f4\u590d\u6742\u7684\u7f51\u7edc\u4efb\u52a1\u3002<\/p>\n<p>\u4ece\u7f51\u7edc\u5b89\u5168\u7684\u89d2\u5ea6\u6765\u770b\uff0cSOCKS5\u4ee3\u7406\u66f4\u4e3a\u5b89\u5168\u53ef\u9760\u3002\u5b83\u652f\u6301\u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\uff0c\u8fd9\u610f\u5473\u7740\u7528\u6237\u7684\u771f\u5b9eIP\u5730\u5740\u80fd\u591f\u5f97\u5230\u66f4\u597d\u7684\u4fdd\u62a4\u3002\u6b64\u5916\uff0cSOCKS5\u4ee3\u7406\u8fd8\u5141\u8bb8\u6d41\u91cf\u7684\u9759\u6001\u5206\u53d1\uff0c\u907f\u514d\u4e86\u7531\u4e8eHTTP\u4ee3\u7406\u9020\u6210\u7684\u6570\u636e\u4e22\u5931\uff0c\u786e\u4fdd\u4e86\u6570\u636e\u63d0\u53d6\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u9009\u62e9SOCKS5\u8fdb\u884c\u7f51\u9875\u6293\u53d6<\/h3>\n<p>\u9009\u62e9<strong>SOCKS5\u4ee3\u7406<\/strong>\u8fdb\u884c\u7f51\u9875\u6293\u53d6\uff0c\u80fd\u591f\u52a9\u529b\u5f00\u53d1\u4eba\u5458\u5728\u9ad8\u5f3a\u5ea6\u7684\u6570\u636e\u63d0\u53d6\u4efb\u52a1\u4e2d\u63d0\u5347\u6548\u7387\u3002\u9996\u5148\uff0cSOCKS5\u7684\u533f\u540d\u6027\u80fd\u591f\u6709\u6548\u907f\u514d\u591a\u6b21\u8bf7\u6c42\u540c\u4e00\u7f51\u7ad9\u65f6\uff0c\u88ab\u7f51\u7ad9\u8bc6\u522b\u4e3a\u975e\u6b63\u5e38\u6d41\u91cf\uff0c\u4ece\u800c\u5f15\u53d1\u5c01\u7981\u3002<\/p>\n<p>\u5176\u6b21\uff0cSOCKS5\u5728\u4f20\u8f93\u6570\u636e\u65f6\u4e0d\u4f1a\u4fee\u6539\u6570\u636e\u5305\u7684\u5185\u5bb9\uff0c\u8fd9\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u51c6\u786e\u6027\u3002\u5728\u5b9e\u73b0\u590d\u6742\u7684\u6293\u53d6\u7b56\u7565\u65f6\uff0c\u7528\u6237\u4e0d\u5fc5\u62c5\u5fe7\u6570\u636e\u7684\u5e72\u6270\u3002\u6b64\u5916\uff0cSOCKS5\u4ee3\u7406\u7684\u7075\u6d3b\u6027\u4f7f\u5176\u80fd\u591f\u5728\u5404\u79cd\u7f51\u7edc\u73af\u5883\u4e2d\u8868\u73b0\u826f\u597d\uff0c\u786e\u4fdd\u7f51\u7edc\u8bf7\u6c42\u7684\u987a\u7545\u8fdb\u884c\u3002<\/p>\n<h3>\u4f7f\u7528SOCKS5\u4ee3\u7406\u7684\u5178\u578b\u573a\u666f<\/h3>\n<p>\u4f7f\u7528<strong>SOCKS5\u4ee3\u7406<\/strong>\u7684\u5178\u578b\u573a\u666f\u5305\u62ec\u6570\u636e\u91c7\u96c6\u3001\u8de8\u5883\u7535\u5546\u3001\u7f51\u7edc\u5b89\u5168\u53ca\u9690\u79c1\u4fdd\u62a4\u7b49\u3002\u5728\u8fdb\u884c\u7f51\u9875\u6293\u53d6\u65f6\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u9700\u8981\u767b\u5f55\u7684\u7f51\u7ad9\u65f6\uff0cSOCKS5\u7684\u8eab\u4efd\u9a8c\u8bc1\u529f\u80fd\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<p>\u800c\u5728\u7535\u5546\u9886\u57df\uff0c\u6e17\u900f\u5230\u5176\u4ed6\u56fd\u5bb6\u5e02\u573a\u7684\u9700\u6c42\u4e5f\u8d8a\u53d1\u660e\u663e\u3002\u501f\u52a9SOCKS5\u4ee3\u7406\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u8f7b\u677e\u7ed5\u8fc7\u5730\u57df\u9650\u5236\uff0c\u83b7\u53d6\u4e0d\u540c\u5730\u533a\u7684\u4fe1\u606f\uff0c\u52a9\u529b\u5546\u4e1a\u51b3\u7b56\u3002<\/p>\n<h3>\u7ed3\u5408123Proxy\u7684\u4f01\u4e1a\u7ea7\u670d\u52a1<\/h3>\n<p>\u4e3a\u652f\u6491\u5f00\u53d1\u4eba\u5458\u7684\u9700\u6c42\uff0c<strong>123Proxy<\/strong>\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u4f01\u4e1a\u7ea7<strong>SOCKS5\u4ee3\u7406\u670d\u52a1<\/strong>\uff0c\u53ef\u4ee5\u5728\u6570\u636e\u91c7\u96c6\u4efb\u52a1\u4e2d\u4e3a\u7528\u6237\u63d0\u4f9b\u4e13\u4e1a\u652f\u6301\u3002\u65e0\u8bba\u662f\u9700\u8981\u7a33\u5b9a\u8fde\u63a5\u7684\u7528\u6237\uff0c\u8fd8\u662f\u5e0c\u671b\u4fdd\u62a4IP\u5730\u5740\u7684\u9690\u79c1\u7528\u6237\uff0c123Proxy\u5747\u53ef\u4ee5\u901a\u8fc7\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u6ee1\u8db3\u5176\u9700\u6c42\u3002\u7528\u6237\u53ef\u901a\u8fc7123Proxy\u83b7\u53d6\u9ad8\u8d28\u91cf\u7684\u4ee3\u7406\u5217\u8868\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347\u6570\u636e\u6293\u53d6\u4efb\u52a1\u7684\u6210\u529f\u7387\u3002<\/p>\n<h2>Scrapy\u4e0eSOCKS5\u4ee3\u7406\u7684\u96c6\u6210\u6311\u6218<\/h2>\n<p><iframe style=\"aspect-ratio: 16 \/ 9; width: 100%\" src=\"https:\/\/www.youtube.com\/embed\/M4I7keMn9rM\" title=\"M4I7keMn9rM\" frameBorder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowFullScreen><\/iframe><\/p>\n<h3>Scrapy\u6846\u67b6\u7684\u57fa\u672c\u4ecb\u7ecd<\/h3>\n<p>Scrapy\u662f\u4e00\u79cd\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u6293\u53d6\u7684\u5f00\u6e90\u6846\u67b6\uff0c\u7279\u522b\u9002\u5408\u4ece\u7f51\u9875\u83b7\u53d6\u6570\u636e\u3002\u5b83\u4ee5\u9ad8\u6548\u7684\u5f02\u6b65\u7f51\u7edc\u722c\u866b\u673a\u5236\u8457\u79f0\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u800c\u8f7b\u677e\u5730\u63d0\u53d6\u548c\u5904\u7406\u6570\u636e\u3002Scrapy\u4f7f\u7528Python\u7f16\u5199\uff0c\u5176\u6a21\u5757\u5316\u67b6\u6784\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528\u5404\u79cd\u6269\u5c55\u529f\u80fd\uff0c\u5982\u4e2d\u95f4\u4ef6\u548c\u4e0b\u8f7d\u5668\u3002\u5bf9\u5f00\u53d1\u8005\u6765\u8bf4\uff0cScrapy\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684API\uff0c\u8fd8\u5177\u6709\u826f\u597d\u7684\u6587\u6863\u652f\u6301\uff0c\u6709\u52a9\u4e8e\u5feb\u901f\u5165\u95e8\u3002<\/p>\n<p>Scrapy\u6846\u67b6\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u9ad8\u5ea6\u53ef\u6269\u5c55\u6027\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u9700\u6c42\u5b9a\u5236\u5176\u529f\u80fd\u3002\u7136\u800c\uff0c\u5728\u4e0e\u4ee3\u7406\u96c6\u6210\u65f6\uff0cScrapy\u7684\u914d\u7f6e\u548c\u8bbe\u7f6e\u663e\u5f97\u5c24\u4e3a\u590d\u6742\uff0c\u7279\u522b\u662f\u5bf9\u4e8eSOCKS5\u4ee3\u7406\u7684\u652f\u6301\u3002\u76ee\u524d\uff0cScrapy\u5bf9SOCKS5\u7684\u539f\u751f\u652f\u6301\u5e76\u4e0d\u7406\u60f3\uff0c\u8fd9\u7ed9\u4f7f\u7528\u8be5\u7c7b\u4ee3\u7406\u8fdb\u884c\u9ad8\u6548\u7f51\u7edc\u6293\u53d6\u7684\u5f00\u53d1\u8005\u5e26\u6765\u4e86\u6311\u6218\u3002<\/p>\n<h3>Scrapy\u67b6\u6784\u5bf9SOCKS5\u4ee3\u7406\u7684\u9650\u5236<\/h3>\n<p>Scrapy\u7684\u67b6\u6784\u672c\u8eab\u5bf9SOCKS5\u4ee3\u7406\u7684\u4f7f\u7528\u5b58\u5728\u4e00\u5b9a\u7684\u5c40\u9650\u6027\u3002\u9996\u5148\uff0cScrapy\u7684\u8bbe\u8ba1\u521d\u8877\u5e76\u672a\u5c06SOCKS5\u4ee3\u7406\u7eb3\u5165\u5176\u6838\u5fc3\u529f\u80fd\u4e4b\u4e00\uff0c\u8fd9\u5bfc\u81f4\u5176\u65e0\u6cd5\u539f\u751f\u652f\u6301\u6b64\u7c7b\u4ee3\u7406\u3002\u6839\u636eGitHub\u4e0a\u7684\u8ba8\u8bba\uff08\u4f8b\u5982\uff0c\u95ee\u9898#747\uff09\uff0cScrapy\u7684\u5904\u7406\u6d41\u7a0b\u5e76\u4e0d\u76f4\u89c2\u5730\u9002\u5e94SOCKS5\u4ee3\u7406\u7684\u63a5\u5165\u3002SOCKS5\u4ee3\u7406\u7684\u7f51\u7edc\u8fde\u63a5\u65b9\u5f0f\u4e0e\u4e00\u822cHTTP\u4ee3\u7406\u4e0d\u540c\uff0c\u56e0\u800c\u5728\u914d\u7f6e\u65f6\u5fc5\u987b\u8003\u8651\u66f4\u4e3a\u590d\u6742\u7684\u8def\u7531\u548c\u4f20\u8f93\u8bbe\u7f6e\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u7531\u4e8eSOCKS5\u7684\u9ad8\u533f\u540d\u6027\uff0c\u5f00\u53d1\u8005\u5728\u4f7f\u7528Scrapy\u722c\u53d6\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u4f1a\u9762\u4e34\u989d\u5916\u7684\u6311\u6218\uff0c\u5305\u62ec\u5904\u7406IP\u5730\u5740\u906e\u853d\u548c\u6570\u636e\u4f20\u8f93\u5ef6\u8fdf\u7b49\u95ee\u9898\u3002\u8fd9\u4e9b\u7279\u6027\u4f7f\u5f97SOCKS5\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u6bd4HTTP\u4ee3\u7406\u66f4\u52a0\u53ef\u9760\uff0c\u4f46\u76f8\u5bf9\u800c\u8a00\uff0c\u5b83\u7684\u6574\u5408\u8fc7\u7a0b\u4e5f\u8981\u6c42\u66f4\u9ad8\u7684\u6280\u672f\u80fd\u529b\u3002<\/p>\n<h3>\u793e\u533a\u8ba8\u8bba\u4e0e\u89e3\u51b3\u65b9\u6848\u80cc\u666f<\/h3>\n<p>\u5728Scrapy\u7684\u7528\u6237\u793e\u533a\u4e2d\uff0c\u5bf9SOCKS5\u4ee3\u7406\u7684\u96c6\u6210\u95ee\u9898\u4e00\u76f4\u662f\u70ed\u95e8\u8bdd\u9898\u3002\u8bb8\u591a\u5f00\u53d1\u8005\u5206\u4eab\u4e86\u4ed6\u4eec\u7684\u7ecf\u9a8c\u4e0e\u6559\u8bad\uff0c\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7\u5404\u79cd\u65b9\u6cd5\u5b9e\u73b0SOCKS5\u4ee3\u7406\u7684\u6709\u6548\u914d\u7f6e\u3002\u793e\u533a\u4e2d\u7684\u4e00\u4e9b\u89e3\u51b3\u65b9\u6848\u5305\u62ec\u4f7f\u7528Docker\u6765\u521b\u5efa\u4ee3\u7406\u73af\u5883\uff0c\u6216\u8005\u5229\u7528\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u6765\u5904\u7406SOCKS5\u8fde\u63a5\u3002<\/p>\n<p>\u4e00\u4e9b\u8d44\u6e90\u5982ZenRows\u548cOxylabs\u63d0\u4f9b\u7684\u6307\u5bfc\uff0c\u5f3a\u8c03\u4e86\u6dfb\u52a0\u5143\u53c2\u6570\u6216\u4f7f\u7528\u4ee3\u7406\u4e2d\u95f4\u4ef6\u7684\u91cd\u8981\u6027\u3002\u8fd9\u4e9b\u7b56\u7565\u4e0d\u4ec5\u6709\u52a9\u4e8e\u63d0\u9ad8\u8fde\u63a5\u7684\u7a33\u5b9a\u6027\uff0c\u8fd8\u80fd\u66f4\u597d\u5730\u7ba1\u7406\u722c\u866b\u7684\u6027\u80fd\u8868\u73b0\u3002\u901a\u8fc7\u8fd9\u4e9b\u793e\u533a\u7684\u8ba8\u8bba\u4e0e\u53cd\u9988\uff0c\u5f00\u53d1\u8005\u4eec\u80fd\u591f\u627e\u5230\u9002\u5408\u81ea\u5df1\u9879\u76ee\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h3>\u73b0\u6709\u539f\u751f\u652f\u6301\u7684\u4e0d\u8db3\u4e4b\u5904<\/h3>\n<p>Scrapy\u5f53\u524d\u5bf9SOCKS5\u4ee3\u7406\u7684\u539f\u751f\u652f\u6301\u4ecd\u7136\u4e0d\u8db3\uff0c\u8bb8\u591a\u529f\u80fd\u65e0\u6cd5\u76f4\u63a5\u5e94\u7528\u4e8eSOCKS5\u4ee3\u7406\u7684\u73af\u5883\u3002\u8fd9\u4e00\u7f3a\u9677\u53ef\u80fd\u5bfc\u81f4\u5f00\u53d1\u4eba\u5458\u5728\u5904\u7406\u4ee3\u7406\u8bf7\u6c42\u65f6\u906d\u9047\u56f0\u96be\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u9ad8\u9891\u7387\u548c\u9ad8\u5e76\u53d1\u6570\u636e\u6293\u53d6\u7684\u573a\u666f\u4e2d\u3002<\/p>\n<p>\u7f3a\u4e4f\u5bf9SOCKS5\u7684\u76f4\u63a5\u652f\u6301\uff0c\u8feb\u4f7f\u5f00\u53d1\u8005\u5fc5\u987b\u4f9d\u8d56\u5176\u4ed6\u65b9\u6cd5\u6765\u5f25\u8865\u8fd9\u4e00\u77ed\u677f\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6216\u63d2\u4ef6\uff0c\u800c\u8fd9\u4e9b\u9009\u9879\u5e76\u4e0d\u603b\u662f\u53ef\u9760\u6216\u6613\u4e8e\u4f7f\u7528\u3002\u5728\u9009\u62e9\u8fd9\u4e9b\u65b9\u6cd5\u65f6\uff0c\u5f00\u53d1\u8005\u9700\u8c28\u614e\u8bc4\u4f30\u5176\u5bf9\u9879\u76ee\u6574\u4f53\u67b6\u6784\u7684\u5f71\u54cd\uff0c\u4ee5\u53ca\u662f\u5426\u80fd\u6709\u6548\u6ee1\u8db3\u6570\u636e\u6293\u53d6\u9700\u6c42\u3002<\/p>\n<h3>\u9700\u8981\u8003\u8651\u7684\u96c6\u6210\u5de5\u5177\u548c\u6280\u672f<\/h3>\n<p>\u9762\u5bf9Scrapy\u4e0eSOCKS5\u4ee3\u7406\u96c6\u6210\u7684\u6311\u6218\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u8003\u8651\u591a\u79cd\u5de5\u5177\u548c\u6280\u672f\u3002\u9996\u5148\uff0cDocker\u4f5c\u4e3a\u4e00\u79cd\u5bb9\u5668\u5316\u5de5\u5177\uff0c\u80fd\u591f\u5e2e\u52a9\u521b\u5efa\u9694\u79bb\u7684\u73af\u5883\uff0c\u5e76\u7b80\u5316SOCKS5\u4ee3\u7406\u7684\u914d\u7f6e\u4e0e\u4f7f\u7528\u3002\u901a\u8fc7Docker\uff0c\u5f00\u53d1\u8005\u80fd\u907f\u514d\u4e0e\u672c\u5730\u73af\u5883\u7684\u591a\u91cd\u4f9d\u8d56\uff0c\u51cf\u5c11\u914d\u7f6e\u4e2d\u7684\u590d\u6742\u6027\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u91c7\u7528\u81ea\u5b9a\u4e49\u4ee3\u7406\u4e2d\u95f4\u4ef6\u4e5f\u662f\u975e\u5e38\u5173\u952e\u7684\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u7f16\u5199\u4e2d\u95f4\u4ef6\u6765\u5904\u7406SOCKS5\u4ee3\u7406\u7684\u8fde\u63a5\u548c\u8bf7\u6c42\uff0c\u5229\u7528Python\u7684\u7075\u6d3b\u6027\u521b\u9020\u7b26\u5408\u81ea\u8eab\u9700\u6c42\u7684\u89e3\u51b3\u65b9\u6848\u3002\u7ed3\u5408\u4f7f\u7528\u5143\u53c2\u6570\uff0c\u5982\u8bbe\u7f6e\u8bf7\u6c42\u5934\u548c\u8d85\u65f6\u9650\u5236\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6570\u636e\u6293\u53d6\u7684\u6210\u529f\u7387\u4e0e\u7a33\u5b9a\u6027\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0cScrapy\u4e0eSOCKS5\u4ee3\u7406\u7684\u96c6\u6210\u7ed9\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u4e86\u8bf8\u591a\u6311\u6218\uff0c\u4f46\u901a\u8fc7\u6df1\u5165\u7814\u7a76\u793e\u533a\u89e3\u51b3\u65b9\u6848\u53ca\u5148\u8fdb\u5de5\u5177\u7684\u4f7f\u7528\uff0c\u5f00\u53d1\u8005\u6709\u671b\u627e\u5230\u5408\u9002\u7684\u9014\u5f84\u6765\u5b9e\u73b0\u4ed6\u4eec\u7684\u7f51\u7edc\u6293\u53d6\u76ee\u6807\u3002<\/p>\n<h2>Scrapy\u914d\u7f6eSOCKS5\u4ee3\u7406\u7684\u51c6\u5907\u5de5\u4f5c<\/h2>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/123proxy.cn\/blogs\/wp-content\/uploads\/2024\/10\/f59a6b53-f892-4b07-9cf5-b1df4c90795a.jpeg\" alt=\"RAW photo, a programmer's workspace featuring a laptop with a terminal open, displaying code for using Scrapy with SOCKS5 proxies, warm ambient lighting, high-quality, 8k UHD resolution, with a focus on the screen and coding environment\" width=650 height=430><\/figure>\n<h3>\u73af\u5883\u8981\u6c42\u4e0e\u8bbe\u7f6e<\/h3>\n<p>\u5728\u5f00\u59cb\u4f7f\u7528<strong>Scrapy<\/strong>\u8fdb\u884c\u7f51\u9875\u6293\u53d6\u4e4b\u524d\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u786e\u4fdd\u5176\u5de5\u4f5c\u73af\u5883\u6ee1\u8db3\u4e00\u4e9b\u57fa\u672c\u8981\u6c42\u3002\u8fd9\u4e9b\u8981\u6c42\u5305\u62ecPython\u7684\u5b89\u88c5\u3001Scrapy\u6846\u67b6\u7684\u914d\u7f6e\u4ee5\u53ca\u7f51\u7edc\u73af\u5883\u7684\u7a33\u5b9a\u6027\u3002\u901a\u5e38\uff0cPython\u7248\u672c\u5e94\u8be5\u662f3.6\u6216\u66f4\u9ad8\uff0c\u56e0\u4e3a\u65b0\u7248\u672c\u7684Scrapy\u5bf9\u65e7\u7248\u672c\u7684\u652f\u6301\u6709\u9650\u3002\u6b64\u5916\uff0c\u8fd8\u9700\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\uff0c\u8fd9\u5c06\u76f4\u63a5\u5f71\u54cd\u5230\u540e\u7eed\u4f7f\u7528<strong>SOCKS5\u4ee3\u7406<\/strong>\u7684\u6548\u679c\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u91cd\u8981\u7684\u8003\u8651\u662f\u7f51\u7edc\u8bbe\u7f6e\u3002\u5f00\u53d1\u4eba\u5458\u5e94\u786e\u4fdd\u9632\u706b\u5899\u6216\u5b89\u5168\u8bbe\u7f6e\u4e0d\u4f1a\u963b\u6b62\u6765\u81ea\u4ee3\u7406\u7684\u8fde\u63a5\u8bf7\u6c42\u3002\u4f18\u5316\u7f51\u7edc\u8bbe\u7f6e\u6709\u52a9\u4e8e\u63d0\u9ad8\u6293\u53d6\u7684\u901f\u5ea6\u548c\u6210\u529f\u7387\uff0c\u5c24\u5176\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u8bf7\u6c42\u65f6\u5c24\u4e3a\u91cd\u8981\u3002\u6b64\u65f6\uff0c\u4f7f\u7528\u56fd\u5185\u5916\u4e0d\u540c\u7c7b\u578b\u7684<strong>\u4ee3\u7406<\/strong>\u53ef\u4ee5\u6709\u6548\u7ed5\u8fc7\u7f51\u7edc\u9650\u5236\u3002<\/p>\n<h3>\u6240\u9700\u8f6f\u4ef6\u4e0e\u5e93\u7684\u5b89\u88c5<\/h3>\n<p>\u4e3a\u4e86\u6709\u6548\u4f7f\u7528Scrapy\u4e0eSOCKS5\u4ee3\u7406\uff0c\u5f00\u53d1\u4eba\u5458\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u7684<strong>\u8f6f\u4ef6<\/strong>\u548cPython\u5e93\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5<\/p>\n<div>Socks5\u534f\u8bae\u652f\u6301\u5e93\uff0c\u5982PySocks\uff1a<\/div>\n<blockquote><p>pip install PySocks<\/p><\/blockquote>\n<p>\u63a5\u7740\uff0c\u5b89\u88c5Scrapy\u6846\u67b6\u53ca\u5176\u6240\u9700\u7ec4\u4ef6\uff1a<\/p>\n<blockquote><p>pip install Scrapy<\/p><\/blockquote>\n<p>\u53e6\u5916\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u989d\u5916\u7684\u5de5\u5177\uff0c\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6570\u636e\u6293\u53d6\u7684\u6548\u7387\uff0c\u4f8b\u5982\u4f7f\u7528<strong>ZenRows<\/strong>\u6216<strong>Oxylabs<\/strong>\u7b49\u63d0\u4f9b\u7684\u4ee3\u7406\u670d\u52a1\uff0c\u8fd9\u4e9b\u670d\u52a1\u5f80\u5f80\u5177\u6709\u66f4\u9ad8\u7684\u6210\u529f\u7387\u548c\u53ef\u7528\u6027\u3002<\/p>\n<h3>Docker\u4e0e\u865a\u62df\u73af\u5883\u7684\u642d\u5efa<\/h3>\n<p>\u4f7f\u7528Docker\u642d\u5efa\u865a\u62df\u73af\u5883\u662f\u786e\u4fddScrapy\u4e0eSOCKS5\u4ee3\u7406\u826f\u597d\u96c6\u6210\u7684\u7edd\u4f73\u65b9\u6cd5\u3002Docker\u4e0d\u4ec5\u63d0\u4f9b\u4e86\u9694\u79bb\u7684\u73af\u5883\uff0c\u8fd8\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u6d4b\u8bd5\u4e0d\u540c\u7248\u672c\u7684<strong>Scrapy<\/strong>\u548c\u5176\u4f9d\u8d56\u9879\u3002\u521b\u5efaDocker\u5bb9\u5668\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<blockquote><p>docker run -it &#8211;name scrapy-env python:3.8<\/p><\/blockquote>\n<p>\u8fdb\u5165\u5bb9\u5668\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u91cd\u590d\u4e0a\u8ff0\u7684\u5e93\u5b89\u88c5\u6b65\u9aa4\u3002\u6b64\u5916\uff0c\u4f7f\u7528Docker\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u590d\u6742\u7684\u7f51\u7edc\u7ed3\u6784\uff0c\u652f\u6301\u591a\u4e2a\u4ee3\u7406\u7684\u540c\u65f6\u4f7f\u7528\uff0c\u5e76\u914d\u7f6e\u7279\u5b9a\u7684\u8def\u7531\u89c4\u5219\uff0c\u786e\u4fdd\u6bcf\u4e2a\u8bf7\u6c42\u5747\u901a\u8fc7\u76f8\u5e94\u7684SOCKS5\u4ee3\u7406\u8fdb\u884c\u3002<\/p>\n<h3>\u7f51\u7edc\u914d\u7f6e\u68c0\u67e5\u53ca\u6d4b\u8bd5<\/h3>\n<p>\u4e0e\u6b64\u540c\u65f6\uff0c\u5f00\u53d1\u4eba\u5458\u5fc5\u987b\u5b9a\u671f\u68c0\u67e5\u7f51\u7edc\u914d\u7f6e\uff0c\u4ee5\u786e\u4fdd\u4ee3\u7406\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002\u901a\u8fc7\u8fd0\u884c\u76f8\u5173\u547d\u4ee4\u6765\u6d4b\u8bd5\u4ee3\u7406\u7684\u53ef\u7528\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528curl\u547d\u4ee4\u8fdb\u884c\u7b80\u5355\u6d4b\u8bd5\u3002\u4f8b\u5982\uff0c\u68c0\u67e5\u5916\u90e8IP\u5730\u5740\uff1a<\/p>\n<blockquote><p>curl &#8211;socks5 <\u4ee3\u7406\u5730\u5740> http:\/\/api.ipify.org<\/p><\/blockquote>\n<p>\u6b64\u5916\uff0c\u8fdb\u884c\u6293\u53d6\u4efb\u52a1\u4e4b\u524d\uff0c\u5efa\u8bae\u5728Scrapy\u9879\u76ee\u4e2d\u8bbe\u7f6e\u7b80\u5355\u7684\u6d4b\u8bd5\u6293\u53d6\uff0c\u9a8c\u8bc1SOCKS5\u4ee3\u7406\u662f\u5426\u5728\u9879\u76ee\u4e2d\u88ab\u6b63\u786e\u8c03\u7528\u3002\u8fd9\u6837\u7684\u6d4b\u8bd5\u662f\u9879\u76ee\u7a33\u5b9a\u8fd0\u884c\u7684\u91cd\u8981\u4fdd\u969c\uff0c\u6709\u52a9\u4e8e\u4f18\u5316\u6293\u53d6\u7b56\u7565\u3002<\/p>\n<h3>123Proxy\u670d\u52a1\u7684\u6ce8\u518c\u4e0e\u83b7\u53d6<\/h3>\n<p>\u6700\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u901a\u8fc7\u6ce8\u518c<strong>123Proxy<\/strong>\u670d\u52a1\u83b7\u53d6\u4f18\u8d28\u7684\u4ee3\u7406\u8d44\u6e90\u3002123Proxy\u63d0\u4f9b\u591a\u79cd\u7c7b\u522b\u7684<strong>HTTP\u4ee3\u7406<\/strong>\uff0c\u5305\u62ec\u5c45\u6c11\u4ee3\u7406\u548c\u6570\u636e\u4e2d\u5fc3\u4ee3\u7406\uff0c\u6839\u636e\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u4ee3\u7406\u7c7b\u578b\u81f3\u5173\u91cd\u8981\u3002\u5728\u6ce8\u518c\u4e4b\u540e\uff0c\u5f00\u53d1\u8005\u5c06\u6536\u5230\u81ea\u5df1\u7684\u4ee3\u7406\u5217\u8868\u548c\u914d\u7f6e\u4fe1\u606f\uff0c\u786e\u4fdd\u5728Scrapy\u9879\u76ee\u4e2d\u80fd\u987a\u5229\u4f7f\u7528SOCKS5\u4ee3\u7406\u3002<\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u5b8c\u6210\u6ce8\u518c\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728Scrapy\u9879\u76ee\u4e2d\u914d\u7f6e\u4f7f\u7528\uff0c\u63d0\u5347\u6570\u636e\u6293\u53d6\u8fc7\u7a0b\u4e2d\u5bf9\u7f51\u7edc\u5b89\u5168\u548c\u7528\u6237\u9690\u79c1\u7684\u7ef4\u62a4\u3002\u540c\u65f6\uff0c123Proxy\u670d\u52a1\u7684\u9ad8\u53ef\u7528\u6027\u548c\u5feb\u901f\u54cd\u5e94\u7279\u6027\uff0c\u53ef\u4ee5\u51cf\u5c11\u6293\u53d6\u8fc7\u7a0b\u4e2d\u7684\u95ee\u9898\uff0c\u63d0\u9ad8\u6574\u4f53\u7684\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<h2>\u5728Scrapy\u4e2d\u5b9e\u73b0SOCKS5\u4ee3\u7406\u914d\u7f6e<\/h2>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/123proxy.cn\/blogs\/wp-content\/uploads\/2024\/10\/fe0e4fbf-1106-4b2e-aaf7-b8718279185e.jpeg\" alt=\"RAW photo, an overhead shot of a modern workspace filled with tech gadgets, including a computer running Scrapy with SOCKS5 proxy configurations on the screen, ambient lighting enhancing the techy feel, 8k UHD resolution, capturing the essence of a digital nomad lifestyle in programming\" width=650 height=430><\/figure>\n<h3>\u914d\u7f6e\u6587\u4ef6\u7684\u7f16\u8f91\u4e0e\u53c2\u6570\u8bbe\u7f6e<\/h3>\n<p>\u5728Scrapy\u4e2d\uff0c\u914d\u7f6eSOCKS5\u4ee3\u7406\u7684\u7b2c\u4e00\u6b65\u662f\u7f16\u8f91<code>settings.py<\/code>\u914d\u7f6e\u6587\u4ef6\u3002\u914d\u7f6e\u6587\u4ef6\u662fScrapy\u9879\u76ee\u7684\u6838\u5fc3\uff0c\u6240\u6709\u7684\u6293\u53d6\u884c\u4e3a\u548c\u8bbe\u7f6e\u90fd\u5728\u6b64\u8fdb\u884c\u5b9a\u4e49\u3002\u4e3a\u4e86\u4f7f\u7528SOCKS5\u4ee3\u7406\uff0c\u5f00\u53d1\u8005\u9700\u8981\u6dfb\u52a0\u5fc5\u8981\u7684\u4ee3\u7406\u53c2\u6570\uff0c\u4f8b\u5982\u4ee3\u7406\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5178\u578b\u7684\u914d\u7f6e\u793a\u4f8b\uff0c\u5047\u8bbe\u4ee3\u7406\u5730\u5740\u4e3a<code>192.168.1.1<\/code>\uff0c\u7aef\u53e3\u4e3a<code>1080<\/code>\uff1a<\/p>\n<ul>\n<li><code>PROXY = 'socks5:\/\/192.168.1.1:1080'<\/code><\/li>\n<li><code>DOWNLOADER_MIDDLEWARES = {'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110, 'myproject.middlewares.Socks5ProxyMiddleware': 100}<\/code><\/li>\n<\/ul>\n<p>\u914d\u7f6e\u8fd9\u4e9b\u53c2\u6570\u540e\uff0cScrapy\u5c06\u80fd\u591f\u901a\u8fc7\u6307\u5b9a\u7684SOCKS5\u4ee3\u7406\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u9ad8\u6570\u636e\u6293\u53d6\u7684\u6548\u7387\u548c\u533f\u540d\u6027\u3002<\/p>\n<h3>\u6dfb\u52a0meta\u53c2\u6570\u4ee5\u652f\u6301\u4ee3\u7406<\/h3>\n<p>\u5728Scrapy\u4e2d\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0<code>meta<\/code>\u53c2\u6570\u6765\u7075\u6d3b\u5730\u652f\u6301\u4ee3\u7406\u3002<code>meta<\/code>\u5b57\u5178\u5141\u8bb8\u5f00\u53d1\u8005\u4f20\u9012\u9644\u52a0\u4fe1\u606f\uff0c\u4f8b\u5982\u8bf7\u6c42\u7684\u4ee3\u7406\u4fe1\u606f\uff0c\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u5bf9\u4e0d\u540c\u8bf7\u6c42\u4f7f\u7528\u4e0d\u540c\u7684\u4ee3\u7406\uff0c\u63d0\u5347\u4e86\u6570\u636e\u6293\u53d6\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<p>\u4f7f\u7528<code>meta<\/code>\u53c2\u6570\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>yield scrapy.Request(url='http:\/\/example.com', meta={'proxy': 'socks5:\/\/192.168.1.1:1080'})<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cScrapy\u5c06\u4f7f\u7528\u6307\u5b9a\u7684SOCKS5\u4ee3\u7406\u5904\u7406\u8be5\u8bf7\u6c42\uff0c\u786e\u4fdd\u8bf7\u6c42\u7684\u6b63\u5e38\u53d1\u9001\u548c\u8fd4\u56de\u3002<\/p>\n<h3>\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u7684\u7f16\u5199\u6b65\u9aa4<\/h3>\n<p>\u7531\u4e8eScrapy\u5bf9SOCKS5\u4ee3\u7406\u7684\u539f\u751f\u652f\u6301\u7f3a\u4e4f\uff0c\u5f00\u53d1\u8005\u901a\u5e38\u9700\u8981\u521b\u5efa\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u4ee5\u652f\u6301\u8be5\u529f\u80fd\u3002\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u5728\u8bf7\u6c42\u548c\u54cd\u5e94\u4e4b\u95f4\u63d2\u5165\u81ea\u5b9a\u4e49\u903b\u8f91\u3002<\/p>\n<p>\u7f16\u5199\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u7684\u57fa\u672c\u6b65\u9aa4\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>\u5728<code>middlewares.py<\/code>\u4e2d\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u7c7b\u3002<\/li>\n<li>\u5b9e\u73b0<code>process_request<\/code>\u65b9\u6cd5\u4ee5\u5c06\u4ee3\u7406\u53c2\u6570\u6dfb\u52a0\u5230\u8bf7\u6c42\u4e2d\u3002<\/li>\n<li>\u5c06\u4e2d\u95f4\u4ef6\u6dfb\u52a0\u5230<code>DOWNLOADER_MIDDLEWARES<\/code>\u8bbe\u7f6e\u4e2d\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre><code>class Socks5ProxyMiddleware:\n    def process_request(self, request, spider):\n        request.meta['proxy'] = 'socks5:\/\/192.168.1.1:1080'<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0SOCKS5\u4ee3\u7406\u7684\u652f\u6301\uff0c\u4ee5\u5e94\u5bf9\u4e0d\u540c\u7684\u6293\u53d6\u9700\u6c42\u3002<\/p>\n<h3>\u4ee3\u7801\u793a\u4f8b\u4e0e\u6ce8\u91ca\u89e3\u6790<\/h3>\n<p>\u7ed3\u5408\u4e0a\u8ff0\u914d\u7f6e\uff0c\u4e0b\u9762\u63d0\u4f9b\u4e00\u4e2a\u5b8c\u6574\u7684\u4f7f\u7528SOCKS5\u4ee3\u7406\u7684Scrapy\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code>import scrapy\n\nclass ExampleSpider(scrapy.Spider):\n    name = 'example'\n    start_urls = ['http:\/\/example.com']\n\n    def start_requests(self):\n        for url in self.start_urls:\n            yield scrapy.Request(url=url, meta={'proxy': 'socks5:\/\/192.168.1.1:1080'})\n\n    def parse(self, response):\n        self.log('Visited %s' % response.url)<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>start_requests<\/code>\u65b9\u6cd5\u5c06\u4f7f\u7528\u6307\u5b9a\u7684SOCKS5\u4ee3\u7406\u53d1\u8d77\u8bf7\u6c42\uff0c<code>parse<\/code>\u65b9\u6cd5\u5219\u8bb0\u5f55\u8bbf\u95ee\u7684\u9875\u9762\u4fe1\u606f\u3002\u8fd9\u79cd\u7ed3\u6784\u4f7f\u5f97Scrapy\u66f4\u4e3a\u9ad8\u6548\u548c\u7075\u6d3b\uff0c\u9002\u5408\u5927\u89c4\u6a21\u6570\u636e\u6293\u53d6\u4efb\u52a1\u3002<\/p>\n<h3>\u5e38\u89c1\u9519\u8bef\u6392\u67e5\u4e0e\u89e3\u51b3<\/h3>\n<p>\u5728\u5b9e\u65bdSOCKS5\u4ee3\u7406\u914d\u7f6e\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u8d26\u6237\u8fc7\u671f\u3001\u4ee3\u7406\u4e0d\u53ef\u7528\u6216\u9519\u8bef\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u914d\u7f6e\u7b49\u95ee\u9898\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bf7\u6c42\u5931\u8d25\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5\u4ee3\u7406\u7684\u6709\u6548\u6027\uff1a\u4f7f\u7528\u7f51\u7edc\u5de5\u5177\u9a8c\u8bc1\u4ee3\u7406\u662f\u5426\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<li>\u67e5\u770bScrapy\u7684\u65e5\u5fd7\u4fe1\u606f\uff1a\u5728<code>settings.py<\/code>\u4e2d\u5f00\u542fDEBUG\u6a21\u5f0f\uff0c\u4ee5\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<li>\u6df1\u5165\u793e\u533a\u8ba8\u8bba\u5e73\u53f0\uff0c\u5982<code>GitHub<\/code>\u548c<code>Stack Overflow<\/code>\uff0c\u83b7\u53d6\u4ed6\u4eba\u89e3\u51b3\u7c7b\u4f3c\u95ee\u9898\u7684\u65b9\u6848\u3002<\/li>\n<\/ul>\n<p>\u5728\u6392\u67e5\u548c\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u65f6\uff0c\u4fdd\u6301\u7ec6\u81f4\u548c\u8010\u5fc3\u662f\u5341\u5206\u91cd\u8981\u7684\u3002\u901a\u8fc7\u6b63\u786e\u7684\u914d\u7f6e\u4e0e\u6709\u6548\u7684\u9519\u8bef\u6392\u67e5\uff0c\u5f00\u53d1\u8005\u5c06\u80fd\u591f\u987a\u5229\u5730\u5728Scrapy\u4e2d\u5b9e\u73b0SOCKS5\u4ee3\u7406\u7684\u914d\u7f6e\uff0c\u6ee1\u8db3\u5404\u7c7b\u7f51\u9875\u6293\u53d6\u9700\u6c42\u3002<\/p>\n<h2>\u6027\u80fd\u4f18\u5316\u4e0e\u5ba2\u6237\u7aef\u8bbe\u7f6e<\/h2>\n<p><iframe style=\"aspect-ratio: 16 \/ 9; width: 100%\" src=\"https:\/\/www.youtube.com\/embed\/snYrTFCvIHQ\" title=\"snYrTFCvIHQ\" frameBorder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowFullScreen><\/iframe><\/p>\n<h3>\u63d0\u9ad8\u6293\u53d6\u901f\u5ea6\u7684\u6280\u5de7<\/h3>\n<p>\u5728\u4f7f\u7528<strong>Scrapy<\/strong>\u548c<strong>SOCKS5<\/strong>\u4ee3\u7406\u8fdb\u884c\u7f51\u9875\u6293\u53d6\u65f6\uff0c\u63d0\u5347\u6293\u53d6\u901f\u5ea6\u662f\u786e\u4fdd\u9879\u76ee\u6210\u529f\u7684\u5173\u952e\u3002\u9996\u5148\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u8bf7\u6c42\u6765\u52a0\u901f\u6293\u53d6\u8fdb\u7a0b\uff0cScrapy\u6709\u5185\u5efa\u7684\u5f02\u6b65\u5904\u7406\u652f\u6301\uff0c\u80fd\u5e76\u884c\u53d1\u9001\u591a\u4e2a\u8bf7\u6c42\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7f51\u9875\u6570\u636e\u63d0\u53d6\u7684\u603b\u4f53\u6548\u7387\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u9002\u5f53\u5730\u914d\u7f6e\u8bf7\u6c42\u95f4\u9694\u548c\u5e76\u53d1\u91cf\uff0c\u53ef\u4ee5\u907f\u514d\u56e0\u76ee\u6807\u7f51\u7ad9\u7684\u901f\u7387\u9650\u5236\u800c\u5bfc\u81f4\u7684\u5c01\u7981\u3002\u901a\u8fc7\u4f7f\u7528Scrapy\u7684\u8bbe\u7f6e\u9879\uff0c\u5982<code>CONCURRENT_REQUESTS<\/code>\u548c<code>DOWNLOAD_DELAY<\/code>\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u7075\u6d3b\u5730\u8c03\u6574\u5e76\u53d1\u8bf7\u6c42\u6570\u4e0e\u8bf7\u6c42\u9891\u7387\uff0c\u4ece\u800c\u627e\u5230\u6700\u4f73\u7684\u6293\u53d6\u8282\u594f\u3002<\/p>\n<p>\u6700\u540e\uff0c\u9009\u62e9\u5408\u9002\u7684<strong>proxy middleware<\/strong>\u548c\u4f18\u5316\u8bf7\u6c42\u5934\u4fe1\u606f\u4e5f\u662f\u63d0\u5347\u6293\u53d6\u901f\u5ea6\u7684\u91cd\u8981\u9014\u5f84\u3002\u5229\u7528\u66f4\u9ad8\u6548\u7684\u4ee3\u7406API\u53ef\u4ee5\u51cf\u5c11\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\uff0c\u52a0\u5feb\u6570\u636e\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<h3>\u8fde\u63a5\u7a33\u5b9a\u6027\u4e0e\u4fdd\u62a4\u9690\u79c1<\/h3>\n<p>\u5728\u6570\u636e\u6293\u53d6\u8fc7\u7a0b\u4e2d\uff0c\u8fde\u63a5\u7684\u7a33\u5b9a\u6027\u76f4\u63a5\u5f71\u54cd\u5230\u6293\u53d6\u7684\u6210\u529f\u7387\u3002\u4f7f\u7528\u5f3a\u5927\u7684<strong>SOCKS5\u4ee3\u7406<\/strong>\u80fd\u591f\u589e\u5f3a\u7f51\u7edc\u8fde\u63a5\u7684\u7a33\u5b9a\u6027\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u91cf\u8bf7\u6c42\u65f6\u3002\u6b64\u5916\uff0cSOCKS5\u4ee3\u7406\u7684<strong>IP\u5730\u5740\u906e\u853d<\/strong>\u529f\u80fd\u80fd\u591f\u6709\u6548\u4fdd\u62a4\u7528\u6237\u7684\u9690\u79c1\uff0c\u4ee5\u53ca\u5728\u6293\u53d6\u8fc7\u7a0b\u4e2d\u51cf\u5c0f\u6570\u5b57\u8db3\u8ff9\uff0c\u4ece\u800c\u907f\u514d\u88ab\u76ee\u6807\u7f51\u7ad9\u68c0\u6d4b\u5230\u3002<\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u5e94\u5b9a\u671f\u66f4\u65b0\u4ee3\u7406\u5217\u8868\uff0c\u4ee5\u786e\u4fdd\u4f7f\u7528\u7684\u4ee3\u7406\u5b9e\u65f6\u6709\u6548\u3002\u9009\u62e9\u5df2\u77e5\u7684\u4f18\u8d28\u4ee3\u7406\u63d0\u4f9b\u5546\uff0c\u5982<strong>ZenRows<\/strong>\u548c<strong>Oxylabs<\/strong>\uff0c\u53ef\u4ee5\u63d0\u9ad8\u8fde\u63a5\u7684\u53ef\u9760\u6027\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5229\u7528\u8fde\u63a5\u76d1\u63a7\u5de5\u5177\u53ef\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5b9e\u65f6\u8ddf\u8e2a\u548c\u5206\u6790\u4ee3\u7406\u7684\u7a33\u5b9a\u6027\uff0c\u53ca\u65f6\u8bc6\u522b\u548c\u89e3\u51b3\u8fde\u63a5\u95ee\u9898\u3002<\/p>\n<h3>\u8d1f\u8f7d\u5747\u8861\u4e0e\u5931\u8d25\u91cd\u8bd5\u7b56\u7565<\/h3>\n<p>\u5728\u8fdb\u884c\u5927\u89c4\u6a21\u6570\u636e\u6293\u53d6\u65f6\uff0c\u5408\u7406\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u5c06\u8bf7\u6c42\u5206\u914d\u5230\u4e0d\u540c\u7684\u4ee3\u7406\u4e0a\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6709\u6548\u5730\u51cf\u8f7b\u5355\u4e2a\u4ee3\u7406\u7684\u8d1f\u62c5\uff0c\u907f\u514d\u56e0\u6d41\u91cf\u8fc7\u8f7d\u800c\u5bfc\u81f4\u7684\u8fde\u63a5\u4e2d\u65ad\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6293\u53d6\u6210\u529f\u7387\uff0c\u5f00\u53d1\u4eba\u5458\u5e94\u8be5\u5b9e\u73b0\u5931\u8d25\u91cd\u8bd5\u7b56\u7565\u3002\u8fd9\u610f\u5473\u7740\u5728\u9047\u5230\u8bf7\u6c42\u5931\u8d25\u65f6\uff0c\u53ef\u4ee5\u81ea\u52a8\u91cd\u8bd5\u8be5\u8bf7\u6c42\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7Scrapy\u4e2d\u5185\u7f6e\u7684<code>RETRY_ENABLED<\/code>\u914d\u7f6e\u8fdb\u884c\u8bbe\u7f6e\uff0c\u5e76\u7ed3\u5408\u9002\u5f53\u7684\u91cd\u8bd5\u6b21\u6570\u548c\u7b49\u5f85\u65f6\u95f4\uff0c\u4f7f\u5f97\u6293\u53d6\u8fc7\u7a0b\u66f4\u52a0\u7a33\u5b9a\u3002<\/p>\n<h3>\u914d\u7f6e\u591a\u4ee3\u7406\u8f6e\u6362\u63d0\u5347\u6293\u53d6\u6210\u529f\u7387<\/h3>\n<p>\u591a\u4ee3\u7406\u8f6e\u6362\u662f\u4e00\u79cd\u6709\u6548\u7684\u63d0\u5347\u6293\u53d6\u6210\u529f\u7387\u7684\u7b56\u7565\u3002\u901a\u8fc7\u5728\u6bcf\u4e2a\u8bf7\u6c42\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u4ee3\u7406\uff0cScrapy\u80fd\u591f\u66f4\u597d\u5730\u5e94\u5bf9\u5404\u79cd\u53cd\u5e94\u63aa\u65bd\uff0c\u51cf\u5c11\u56e0\u9891\u7e41\u4f7f\u7528\u540c\u4e00IP\u800c\u5bfc\u81f4\u7684\u5c01\u7981\u98ce\u9669\u3002\u4e3a\u6b64\uff0c\u6280\u672f\u4eba\u5458\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u81ea\u5b9a\u4e49\u7684<strong>proxy middleware<\/strong>\uff0c\u6765\u5b9e\u73b0\u5bf9\u4ee3\u7406\u7684\u8f6e\u6362\u7ba1\u7406\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5e94\u7528\u4ee3\u7406\u6c60\u673a\u5236\uff0c\u5b9e\u65f6\u68c0\u7d22\u5e76\u66f4\u65b0\u53ef\u7528\u4ee3\u7406\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u8bf7\u6c42\u7684\u6210\u529f\u7387\uff0c\u8fd8\u80fd\u4f18\u5316\u6570\u636e\u6293\u53d6\u7684\u6548\u7387\u3002\u8bb8\u591a\u5f00\u53d1\u793e\u533a\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5173\u8d44\u6e90\u4f9b\u5f00\u53d1\u4eba\u5458\u53c2\u8003\uff0c\u4ece\u800c\u66f4\u597d\u5730\u5b9e\u73b0\u4ee3\u7406\u7684\u7ba1\u7406\u4e0e\u914d\u7f6e\u3002<\/p>\n<h3>\u76d1\u63a7\u4e0e\u65e5\u5fd7\u8bb0\u5f55\u6700\u4f73\u5b9e\u8df5<\/h3>\n<p>\u5728\u8fdb\u884c\u7f51\u9875\u6293\u53d6\u65f6\uff0c\u826f\u597d\u7684\u76d1\u63a7\u4e0e\u65e5\u5fd7\u8bb0\u5f55\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u4e3b\u52a8\u89e3\u51b3\u6f5c\u5728\u95ee\u9898\u3002Scrapy\u63d0\u4f9b\u65e5\u5fd7\u529f\u80fd\uff0c\u53ef\u4ee5\u8bb0\u5f55\u6bcf\u4e2a\u6293\u53d6\u8bf7\u6c42\u7684\u54cd\u5e94\u72b6\u6001\u3001\u4ee3\u7406\u4f7f\u7528\u60c5\u51b5\u7b49\u5173\u952e\u4fe1\u606f\u3002<\/p>\n<p>\u901a\u8fc7\u5206\u6790\u65e5\u5fd7\u6570\u636e\uff0c\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u5feb\u901f\u8bc6\u522b\u8bf7\u6c42\u5931\u8d25\u7684\u539f\u56e0\uff0c\u4ece\u800c\u8fdb\u884c\u76f8\u5e94\u7684\u8c03\u6574\u3002\u540c\u65f6\uff0c\u76d1\u63a7\u6293\u53d6\u8fdb\u5ea6\uff0c\u53ca\u65f6\u53d1\u73b0\u5f02\u5e38\u8fde\u63a5\u6216\u6027\u80fd\u74f6\u9888\uff0c\u786e\u4fdd\u6570\u636e\u6293\u53d6\u6d3b\u52a8\u7684\u9ad8\u6548\u8fdb\u884c\u3002<\/p>\n<p>\u4eba\u5458\u8fd8\u53ef\u5229\u7528\u7b2c\u4e09\u65b9\u76d1\u63a7\u5de5\u5177\u52a0\u5f3a\u76d1\u63a7\u9891\u5ea6\uff0c\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5b9e\u65f6\u53cd\u9988\u4ee3\u7406\u7684\u6027\u80fd\u60c5\u51b5\uff0c\u5e76\u63d0\u4f9b\u8b66\u62a5\u670d\u52a1\uff0c\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u54cd\u5e94\u8fde\u63a5\u95ee\u9898\u3002<\/p>\n<h2>Scrapy\u6293\u53d6\u9879\u76ee\u4e2d\u7684SOCKS5\u4ee3\u7406\u4f7f\u7528<\/h2>\n<p><iframe style=\"aspect-ratio: 16 \/ 9; width: 100%\" src=\"https:\/\/www.youtube.com\/embed\/2gXE86ypgvA\" title=\"2gXE86ypgvA\" frameBorder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowFullScreen><\/iframe><\/p>\n<h3>\u5b9e\u9645\u9879\u76ee\u4e2d\u7684\u5e94\u7528\u793a\u4f8b<\/h3>\n<p>\u5728\u5b9e\u9645\u7684<em>Scrapy<\/em>\u9879\u76ee\u4e2d\uff0c\u4f7f\u7528<strong>SOCKS5\u4ee3\u7406<\/strong>\u80fd\u591f\u6709\u6548\u63d0\u5347\u6293\u53d6\u6548\u7387\u548c\u6570\u636e\u5b89\u5168\u6027\u3002\u5c24\u5176\u662f\u5728\u9762\u5bf9\u9700\u8981\u63d0\u9ad8\u533f\u540d\u6027\u548c\u7ed5\u8fc7\u5730\u533a\u9650\u5236\u7684\u573a\u666f\u65f6\uff0cSOCKS5\u4ee3\u7406\u663e\u793a\u51fa\u5176\u72ec\u7279\u7684\u4f18\u52bf\u3002\u4f8b\u5982\uff0c\u5f53\u5f00\u53d1\u4eba\u5458\u9700\u8981\u4ece\u591a\u6837\u5316\u7684\u7f51\u9875\u6293\u53d6\u4fe1\u606f\u65f6\uff0c\u80fd\u591f\u4f7f\u7528SOCKS5\u4ee3\u7406\u4ece\u4e0d\u540c\u5730\u7406\u4f4d\u7f6e\u83b7\u53d6\u6570\u636e\uff0c\u4ece\u800c\u83b7\u5f97\u66f4\u5168\u9762\u7684\u89c6\u89d2\u3002<\/p>\n<p>\u4f7f\u7528<strong>SOCKS5\u4ee3\u7406<\/strong>\u7684\u4e00\u4e2a\u5e38\u89c1\u5e94\u7528\u662f\u5bf9\u8de8\u5883\u7535\u5546\u7f51\u7ad9\u7684\u722c\u53d6\u3002\u5728\u8fd9\u4e9b\u5e73\u53f0\u4e0a\uff0c\u4fe1\u606f\u7684\u9891\u7e41\u66f4\u65b0\u3001\u4f4e\u5ef6\u8fdf\u7684\u8bf7\u6c42\u548c\u907f\u514dIP\u5730\u5740\u88ab\u9650\u5236\u662f\u6210\u529f\u6293\u53d6\u7684\u5173\u952e\u3002\u9009\u62e9\u4f7f\u7528SOCKS5\u4ee3\u7406\u540e\uff0c\u5f00\u53d1\u8005\u80fd\u591f\u5b9a\u5236\u4ed6\u4eec\u7684\u722c\u53d6\u7b56\u7565\u5e76\u5feb\u901f\u5e94\u5bf9\u53cd\u722c\u866b\u63aa\u65bd\u3002<\/p>\n<h3>\u4ee3\u7801\u7247\u6bb5\u4e0e\u529f\u80fd\u6f14\u793a<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u7b80\u5355\u7684\u4ee3\u7801\u7247\u6bb5\u6765\u5b9e\u73b0SOCKS5\u4ee3\u7406\u7684\u914d\u7f6e\u3002\u5728<em>Scrapy<\/em>\u4e2d\uff0c\u9996\u5148\u9700\u8981\u5728\u8bbe\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee3\u7406\u914d\u7f6e\u3002\u4e0b\u5217\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u6765\u5411\u8bf7\u6c42\u6dfb\u52a0SOCKS5\u4ee3\u7406\uff1a<\/p>\n<blockquote><p>from scrapy import signals<\/p>\n<pre>class Socks5ProxyMiddleware(object):<br>    def __init__(self, proxy_port):<br>        self.proxy_port = proxy_port<br>    @classmethod<br>    def from_crawler(cls, crawler):<br>        return cls(crawler.settings.get('PROXY_PORT'))<br>    def process_request(self, request, spider):<br>        request.meta['proxy'] = f'socks5:\/\/{self.proxy_port}'<\/pre>\n<\/blockquote>\n<p>\u5728\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u4e2d\uff0c\u5f00\u53d1\u8005\u901a\u8fc7\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u4ee3\u7406\u7aef\u53e3\uff0c\u52a8\u6001\u5730\u7ed9\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u6dfb\u52a0SOCKS5\u4ee3\u7406\u3002\u8fd9\u6837\u4e00\u6765\uff0cScrapy\u53d1\u9001\u7684\u6240\u6709\u8bf7\u6c42\u90fd\u4f1a\u901a\u8fc7\u6307\u5b9a\u7684SOCKS5\u4ee3\u7406\u8fdb\u884c\u8f6c\u53d1\uff0c\u589e\u5f3a\u4e86\u6293\u53d6\u7684\u7075\u6d3b\u6027\u4e0e\u6709\u6548\u6027\u3002<\/p>\n<h3>\u9879\u76ee\u7ed3\u6784\u4e0e\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406<\/h3>\n<p>\u5728\u722c\u866b\u9879\u76ee\u4e2d\uff0c\u5408\u7406\u7684\u9879\u76ee\u7ed3\u6784\u53ca\u9ad8\u6548\u7684\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u5bf9\u4e8e\u4f7f\u7528SOCKS5\u4ee3\u7406\u7684<em>Scrapy<\/em>\u9879\u76ee\uff0c\u4ee5\u4e0b\u7684\u7ed3\u6784\u53ef\u4ee5\u6709\u6548\u5e2e\u52a9\u5f00\u53d1\u8005\u8fdb\u884c\u7ba1\u7406\uff1a<\/p>\n<ul>\n<li><strong>scrapy_project\/<\/strong>\n<ul>\n<li>spiders\/<\/li>\n<li>middlewares\/<\/li>\n<li>settings.py<\/li>\n<li>items.py<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5176\u4e2d\uff0c<strong>middlewares\/<\/strong>\u6587\u4ef6\u5939\u5b58\u653e\u7740\u81ea\u5b9a\u4e49\u7684\u4e2d\u95f4\u4ef6\u4ee3\u7801\uff0c\u5982\u4e0a\u8ff0\u7684SOCKS5\u4ee3\u7406\u4e2d\u95f4\u4ef6\u3002<strong>settings.py<\/strong>\u6587\u4ef6\u5219\u7528\u4e8e\u914d\u7f6eSOCKS5\u4ee3\u7406\u7684\u7aef\u53e3\u3001\u7528\u6237\u8ba4\u8bc1\u4fe1\u606f\u7b49\uff0c\u786e\u4fdd\u5728\u542f\u52a8\u722c\u866b\u4e4b\u524d\u80fd\u591f\u771f\u5b9e\u4e14\u5b89\u5168\u5730\u5e94\u7528\u4ee3\u7406\u8bbe\u7f6e\u3002<\/p>\n<h3>\u7efc\u5408\u4f7f\u7528\u63d2\u4ef6\u4e0e\u6269\u5c55<\/h3>\n<p>\u4e3a\u4e86\u63d0\u5347\u4f7f\u7528SOCKS5\u4ee3\u7406\u7684\u6548\u7387\uff0c\u8bb8\u591a\u5f00\u53d1\u8005\u7ed3\u5408\u5404\u7c7b\u63d2\u4ef6\u548c\u6269\u5c55\u6765\u8fdb\u4e00\u6b65\u589e\u5f3a\u529f\u80fd\u3002\u4f8b\u5982\uff0c\u5229\u7528<em>Scrapy-Proxy-Pool<\/em>\u81ea\u52a8\u7ba1\u7406IP\u6c60\uff0c\u6216<em>Scrapy-Rotating-Proxies<\/em>\u6765\u52a8\u6001\u5207\u6362\u4ee3\u7406\u65b9\u6cd5\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u51cf\u8f7b\u5f00\u53d1\u8d1f\u62c5\u5e76\u63d0\u9ad8\u6570\u636e\u6293\u53d6\u7684\u6210\u529f\u7387\u3002<\/p>\n<p><strong>\u63d2\u4ef6<\/strong>\u7684\u4f7f\u7528\u4fc3\u8fdb\u4e86\u9879\u76ee\u7684\u6a21\u5757\u5316\uff0c\u4f7f\u5f00\u53d1\u8005\u80fd\u591f\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u65e0\u9700\u8fc7\u591a\u8003\u8651\u7f51\u7edc\u5b89\u5168\u53caIP\u7ba1\u7406\u7684\u95ee\u9898\u3002\u7ed3\u5408\u8fd9\u4e9b\u6280\u672f\u624b\u6bb5\uff0c\u5f00\u53d1\u8005\u80fd\u591f\u6784\u5efa\u51fa\u66f4\u5177\u53ef\u6269\u5c55\u6027\u7684\u6293\u53d6\u7cfb\u7edf\u3002<\/p>\n<h3>\u901a\u8fc7123Proxy\u5b9e\u73b0\u81ea\u52a8\u5316\u7ba1\u7406<\/h3>\n<p>\u901a\u8fc7\u4f7f\u7528<strong>123Proxy<\/strong>\u63d0\u4f9b\u7684\u4f01\u4e1a\u7ea7HTTP\u4ee3\u7406\u670d\u52a1\uff0c\u5f00\u53d1\u8005\u80fd\u591f\u5b9e\u73b0\u5f3a\u5927\u7684\u4ee3\u7406\u7ba1\u7406\uff0c\u63d0\u5347\u6570\u636e\u6293\u53d6\u7684\u7a33\u5b9a\u6027\u548c\u6548\u7387\u3002\u5b8c\u7f8e\u517c\u5bb9\u5404\u79cd\u4ee3\u7406\u7c7b\u578b\uff0c\u5982<strong>\u4f4f\u5b85\u4ee3\u7406<\/strong>\u548c<strong>\u6570\u636e\u4e2d\u5fc3\u4ee3\u7406<\/strong>\uff0c<strong>123Proxy<\/strong>\u7684\u7cfb\u7edf\u8fd8\u80fd\u63d0\u4f9b\u81ea\u52a8\u5316\u7684IP\u8f6e\u6362\u529f\u80fd\uff0c\u786e\u4fdd\u7cfb\u7edf\u5728\u6267\u884c\u6293\u53d6\u65f6\u4e0d\u4f1a\u53d7\u5230\u9650\u5236\u3002<\/p>\n<p>\u6b64\u5916\uff0c<strong>123Proxy<\/strong>\u8fd8\u975e\u5e38\u6ce8\u91cd\u7528\u6237\u9690\u79c1\u4e0e\u7f51\u7edc\u5b89\u5168\uff0c\u63d0\u4f9bIP\u5730\u5740\u63a9\u853d\u53ca\u52a0\u5bc6\u4f20\u8f93\uff0c\u4fdd\u8bc1\u6570\u636e\u83b7\u53d6\u8fc7\u7a0b\u7684\u533f\u540d\u6027\u3002\u901a\u8fc7\u8fd9\u6837\u9ad8\u6548\u800c\u5b89\u5168\u7684\u4ee3\u7406\u670d\u52a1\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u96c6\u4e2d\u7cbe\u529b\u4e8e\u6293\u53d6\u7b56\u7565\u548c\u6570\u636e\u5185\u5bb9\uff0c\u800c\u4e0d\u5fc5\u62c5\u5fc3\u5e95\u5c42\u7684\u7f51\u7edc\u590d\u6742\u6027\u3002<\/p>\n<h2>\u9ad8\u7ea7\u5e94\u7528\u4e0e\u95ee\u9898\u89e3\u51b3<\/h2>\n<h3>\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u4ee3\u7406\u529f\u80fd<\/h3>\n<p>\u5728\u8fdb\u884c\u7f51\u9875\u6293\u53d6\u65f6\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u4f1a\u9700\u8981\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u4ee3\u7406\u529f\u80fd\uff0c\u4ee5\u786e\u4fdd\u5176\u6570\u636e\u6293\u53d6\u8fc7\u7a0b\u66f4\u52a0\u987a\u5229\u548c\u6709\u6548\u3002<strong>SOCKS5\u4ee3\u7406<\/strong>\u51ed\u501f\u5176\u9ad8\u6027\u80fd\u548c\u7075\u6d3b\u6027\uff0c\u5e38\u7528\u4e8e\u5904\u7406\u7279\u5b9a\u9700\u6c42\uff0c\u5982\u91cd\u5b9a\u5411\u548c\u6d41\u91cf\u7ba1\u7406\u3002\u901a\u8fc7\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684 <strong>\u4ee3\u7406\u4e2d\u95f4\u4ef6<\/strong>\uff0c\u53ef\u4ee5\u6700\u5927\u7a0b\u5ea6\u5730\u63d0\u5347\u6570\u636e\u6293\u53d6\u6548\u7387\u6765\u6ee1\u8db3\u590d\u6742\u7684\u5b9a\u5236\u9700\u6c42\u3002<\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u591a\u79cd\u7c7b\u578b\u7684\u4ee3\u7406\uff0c\u4f8b\u5982 <strong>\u4f4f\u5b85\u4ee3\u7406<\/strong>\u548c <strong>\u6570\u636e\u4e2d\u5fc3\u4ee3\u7406<\/strong>\u3002\u8fd9\u4e24\u79cd\u4ee3\u7406\u7c7b\u578b\u5728\u5904\u7406\u9891\u7e41\u7684\u8bf7\u6c42\u548c\u4e0d\u540c\u7684\u7f51\u7edc\u73af\u5883\u65f6\uff0c\u5c55\u793a\u51fa\u5404\u81ea\u7684\u4f18\u52bf\u4e0e\u5c40\u9650\u3002\u901a\u8fc7\u96c6\u6210\u8fd9\u4e9b\u4ee3\u7406\uff0cScrapy\u6846\u67b6\u7684\u6027\u80fd\u53ef\u4ee5\u5f97\u5230\u663e\u8457\u63d0\u5347\u3002<\/p>\n<h3>\u52a8\u6001IP\u7684\u914d\u7f6e\u4e0e\u5207\u6362<\/h3>\n<p>\u4e3a\u907f\u514d\u5728\u6293\u53d6\u8fc7\u7a0b\u4e2d\u88ab\u76ee\u6807\u7f51\u7ad9\u5c4f\u853d\uff0c\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u9700\u8981\u5b9e\u65bd\u52a8\u6001IP\u5207\u6362\u673a\u5236\u3002\u901a\u8fc7\u5229\u7528\u53ef\u66f4\u6362\u7684IP\u8d44\u6e90\uff0cScrapy\u53ef\u4ee5\u5728\u53d1\u51fa\u8bf7\u6c42\u65f6\u968f\u673a\u9009\u62e9IP\uff0c\u589e\u52a0\u533f\u540d\u6027\uff0c\u5e76\u51cf\u5c11\u88ab\u5c01\u7981\u7684\u98ce\u9669\u3002\u8bbe\u7f6e\u52a8\u6001IP\u53ef\u901a\u8fc7\u4f7f\u7528proxy middleware\u914d\u7f6e\u5b9e\u73b0\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u867d\u7136\u590d\u6742\uff0c\u4f46\u80fd\u6709\u6548\u63d0\u5347\u6293\u53d6\u7684\u6210\u529f\u7387\u548c\u6570\u636e\u66f4\u65b0\u7387\u3002<\/p>\n<p>\u5982\u9700\u5b9e\u73b0\u52a8\u6001IP\uff0cScrapy\u7528\u6237\u53ef\u4ee5\u53c2\u8003\u5c01\u88c5\u8bf7\u6c42\u7684 <strong>meta\u53c2\u6570<\/strong>\uff0c\u901a\u8fc7\u5b9e\u73b0\u8ddf\u8e2aIP\u7684\u673a\u5236\uff0c\u786e\u4fdd\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u80fd\u4f7f\u7528\u65b0\u7684IP\u5730\u5740\u8fdb\u884c\u8bbf\u95ee\u3002\u901a\u8fc7\u8fd9\u6837\u7684\u8bbe\u7f6e\uff0c\u6293\u53d6\u8fc7\u7a0b\u4e2d\u7684\u6f5c\u5728\u98ce\u9669\u5c06\u663e\u8457\u964d\u4f4e\u3002<\/p>\n<h3>\u5904\u7406Captcha\u4e0e\u5c01\u7981\u9650\u5236<\/h3>\n<p>\u5728\u7f51\u9875\u6293\u53d6\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u9891\u7e41\u906d\u9047 <strong>Captcha<\/strong> \u9a8c\u8bc1\u548cIP\u5c01\u7981\u7684\u95ee\u9898\u3002\u4e3a\u6b64\uff0c\u4ed6\u4eec\u9700\u8981\u91c7\u53d6\u4e00\u4e9b\u7b56\u7565\u6765\u51cf\u5c11\u8fd9\u4e00\u5f71\u54cd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5b9a\u5236\u7684\u8bf7\u6c42\u95f4\u9694\u3001\u968f\u673a\u7684HTTP\u5934\u90e8\uff0c\u6216\u8005\u4f7f\u7528\u7b2c\u4e09\u65b9\u670d\u52a1\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<p>\u5728\u5904\u7406Captcha\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u5f15\u5165 <strong>\u81ea\u52a8\u5316\u89e3\u51b3\u65b9\u6848<\/strong>\uff0c\u4f8b\u5982\u4f7f\u7528\u4e13\u95e8\u7684API\u6765\u5904\u7406Captcha\u4efb\u52a1\uff0c\u6216\u8005\u901a\u8fc7\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u6765\u8bc6\u522b\u548c\u89e3\u51b3Captcha\u3002\u8fd9\u4e0d\u4ec5\u80fd\u63d0\u9ad8\u6293\u53d6\u7684\u6210\u529f\u7387\uff0c\u8fd8\u6709\u52a9\u4e8e\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\uff0c\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<h3>\u6280\u672f\u652f\u6301\u4e0e\u793e\u533a\u8d44\u6e90<\/h3>\n<p>\u5728\u4f7f\u7528Scrapy\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5229\u7528\u5e7f\u6cdb\u7684\u6280\u672f\u652f\u6301\u4e0e\u793e\u533a\u8d44\u6e90\u3002\u6d3b\u8dc3\u7684Scrapy\u793e\u533a\u5f80\u5f80\u53ef\u4ee5\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u5206\u4eab\u7ecf\u9a8c\u3002\u5728GitHub\u53caStack Overflow\u7b49\u5e73\u53f0\u4e0a\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u627e\u5230\u5f88\u591a\u5173\u4e8e\u4ee3\u7406\u914d\u7f6e\u548c\u4f18\u5316\u6027\u80fd\u7684\u8ba8\u8bba\u3002<\/p>\n<p>\u901a\u8fc7\u53c2\u4e0e\u8fd9\u4e9b\u8bba\u575b\u548c\u8ba8\u8bba\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u83b7\u5f97\u6765\u81ea\u5176\u4ed6\u7528\u6237\u7684\u53cd\u9988\u548c\u6709\u6548\u89e3\u51b3\u65b9\u6848\u3002\u540c\u65f6\uff0c\u4ed6\u4eec\u4e5f\u53ef\u4ee5\u5c06\u81ea\u5df1\u7684\u7ecf\u9a8c\u5206\u4eab\u7ed9\u5176\u4ed6\u793e\u533a\u6210\u5458\uff0c\u4ece\u800c\u4fc3\u8fdb\u77e5\u8bc6\u7684\u4ea4\u6d41\u548c\u63d0\u9ad8\u6574\u4f53\u6280\u672f\u6c34\u5e73\u3002<\/p>\n<h3>\u5229\u7528123Proxy\u83b7\u5f97\u989d\u5916\u652f\u6301<\/h3>\n<p>\u4e3a\u4e86\u83b7\u53d6\u66f4\u4e3a\u4e13\u4e1a\u7684\u652f\u6301\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u9009\u62e9 <strong>123Proxy<\/strong> \u63d0\u4f9b\u7684\u4f01\u4e1a\u7ea7HTTP\u4ee3\u7406IP\u670d\u52a1\u3002123Proxy\u4e0d\u4ec5\u63d0\u4f9b\u591a\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u4ee3\u7406\u9009\u62e9\uff0c\u5982 <strong>SOCKS5\u4ee3\u7406<\/strong>\uff0c\u8fd8\u80fd\u6839\u636e\u9700\u6c42\u5b9a\u5236\u6293\u53d6\u7b56\u7565\uff0c\u63d0\u4f9b\u65e0\u7f1d\u8fde\u63a5\u7684\u7f51\u7edc\u73af\u5883\u3002<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528123Proxy\uff0c\u5f00\u53d1\u4eba\u5458\u4e0d\u4ec5\u80fd\u591f\u4eab\u53d7\u9ad8\u6027\u80fd\u7684\u4ee3\u7406\u670d\u52a1\uff0c\u8fd8\u80fd\u83b7\u53d6\u5230\u66f4\u8be6\u7ec6\u7684\u6280\u672f\u652f\u6301\u4ee5\u53ca\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae\u3002\u65e0\u8bba\u662f\u8fdb\u884c\u6570\u636e\u91c7\u96c6\u8fd8\u662f\u8de8\u5883\u7535\u5546\u9700\u6c42\uff0c123Proxy\u90fd\u5c06\u662f\u63d0\u5347\u6293\u53d6\u6548\u679c\u7684\u91cd\u8981\u5408\u4f5c\u4f19\u4f34\u3002<\/p>\n<h2>\u672a\u6765\u53d1\u5c55\u4e0e\u8d8b\u52bf\u5c55\u671b<\/h2>\n<h3>SOCKS5\u4ee3\u7406\u7684\u53d1\u5c55\u8d8b\u52bf<\/h3>\n<p>\u5728\u5f53\u524d\u7684\u6570\u636e\u83b7\u53d6\u5e02\u573a\u4e2d\uff0c<strong>SOCKS5\u4ee3\u7406<\/strong>\u7684\u5e94\u7528\u6b63\u9010\u6e10\u6269\u5927\u3002\u968f\u7740\u5bf9\u7f51\u7edc\u5b89\u5168\u548c\u7528\u6237\u9690\u79c1\u7684\u5173\u6ce8\u65e5\u76ca\u589e\u52a0\uff0c\u8bb8\u591a\u5f00\u53d1\u4eba\u5458\u548c\u4f01\u4e1a\u5f00\u59cb\u9009\u62e9\u4f7f\u7528<strong>SOCKS5\u4ee3\u7406<\/strong>\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u63d0\u4f9b\u66f4\u9ad8\u7684\u533f\u540d\u6027\u548c\u7075\u6d3b\u6027\u3002\u8fd9\u79cd\u4ee3\u7406\u7c7b\u578b\u652f\u6301\u591a\u79cd\u534f\u8bae\uff0c\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e86\u66f4\u4e3a\u5e7f\u6cdb\u7684\u7f51\u7edc\u8bbf\u95ee\u65b9\u5f0f\u3002\u540c\u65f6\uff0cSOCKS5\u4ee3\u7406\u5728\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u6d41\u91cf\u65b9\u9762\u7684\u8868\u73b0\u4e5f\u663e\u8457\u4f18\u4e8e\u4f20\u7edf\u7684HTTP\u4ee3\u7406\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u968f\u7740\u65b0\u7684\u6280\u672f\u548c\u6807\u51c6\u7684\u51fa\u73b0\uff0cSOCKS5\u4ee3\u7406\u7684\u529f\u80fd\u548c\u6027\u80fd\u4e5f\u5728\u4e0d\u65ad\u6539\u8fdb\u3002\u53d1\u5c55\u8d8b\u52bf\u663e\u793a\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4f9b\u5e94\u5546\u5c06\u5f15\u5165<em>\u52a0\u5bc6\u6280\u672f<\/em>\uff0c\u4ee5\u589e\u5f3a\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u3002\u8fd9\u4f7f\u5f97SOCKS5\u4ee3\u7406\u5728\u8fdb\u884c\u654f\u611f\u6570\u636e\u6293\u53d6\u65f6\u66f4\u5177\u4f18\u52bf\u3002<\/p>\n<h3>\u4ee3\u7406\u6280\u672f\u7684\u521b\u65b0\u4e0e\u53d8\u5316<\/h3>\n<p>\u4ee3\u7406\u6280\u672f\u672c\u8eab\u4e5f\u5728\u7ecf\u5386\u521b\u65b0\u548c\u53d8\u5316\u3002\u5728\u8fc7\u53bb\u7684\u51e0\u5e74\u91cc\uff0c<strong>\u4ee3\u7406middleware<\/strong>\u7684\u6982\u5ff5\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7406\u7684\u884c\u4e3a\uff0c\u63d0\u9ad8\u4e86\u7075\u6d3b\u6027\u548c\u53ef\u63a7\u5236\u6027\u3002\u7ed3\u5408\u4f7f\u7528<em>Docker<\/em>\u7b49\u73b0\u4ee3\u6280\u672f\uff0c\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u66f4\u52a0\u8f7b\u677e\u5730\u7ba1\u7406\u81ea\u5df1\u7684\u6293\u53d6\u73af\u5883\uff0c\u4ece\u800c\u4f18\u5316\u6027\u80fd\u548c\u64cd\u4f5c\u6548\u7387\u3002<\/p>\n<p>\u6b64\u5916\uff0c<strong>\u4ee3\u7406\u5217\u8868<\/strong>\u4e0e<strong>\u4f4f\u5b85\u4ee3\u7406<\/strong>\u7684\u4f7f\u7528\u4e5f\u5728\u4e0d\u65ad\u4e0a\u5347\u3002\u8fd9\u4e9b\u65b0\u6280\u672f\u7684\u96c6\u6210\u4f7f\u5f97\u6570\u636e\u6293\u53d6\u66f4\u52a0\u9ad8\u6548\uff0c\u80fd\u591f\u6709\u6548\u5e94\u5bf9\u9ad8\u590d\u6742\u5ea6\u7684\u7f51\u7ad9\u7ed3\u6784\u548c\u53cd\u722c\u866b\u673a\u5236\u3002<\/p>\n<h3>\u81ea\u52a8\u5316\u7f51\u9875\u6293\u53d6\u7684\u672a\u6765<\/h3>\n<p>\u968f\u7740\u6280\u672f\u7684\u53d1\u5c55\uff0c\u81ea\u52a8\u5316\u7f51\u9875\u6293\u53d6\u9884\u8ba1\u5c06\u8fce\u6765\u65b0\u7684\u9ad8\u5cf0\u3002\u4f01\u4e1a\u548c\u5f00\u53d1\u4eba\u5458\u8d8a\u6765\u8d8a\u503e\u5411\u4e8e\u91c7\u7528\u81ea\u52a8\u5316\u5de5\u5177\u6765\u7b80\u5316\u6570\u636e\u83b7\u53d6\u6d41\u7a0b\u3002\u8fd9\u5c06\u63a8\u52a8\u66f4\u590d\u6742\u548c\u7cbe\u7ec6\u5316\u7684\u6293\u53d6\u7b56\u7565\uff0c\u91c7\u7528\u66f4\u5148\u8fdb\u7684\u7b97\u6cd5\u6765\u5e94\u5bf9\u7f51\u7ad9\u7684\u53d8\u5316\u3002<\/p>\n<p>\u5728\u6b64\u80cc\u666f\u4e0b\uff0c<strong>Scrapy<\/strong>\u4f5c\u4e3a\u4e00\u6b3e\u4e3b\u6d41\u7684\u7f51\u9875\u6293\u53d6\u6846\u67b6\uff0c\u6b63\u4e0d\u65ad\u4f18\u5316\u7528\u6237\u4f53\u9a8c\uff0c\u96c6\u6210\u66f4\u591a\u529f\u80fd\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5728\u8fd9\u4e2a\u5feb\u901f\u53d1\u5c55\u7684\u5e02\u573a\u4e2d\u4fdd\u6301\u7ade\u4e89\u529b\u3002\u6293\u53d6\u7b56\u7565\u4e5f\u5c06\u66f4\u52a0\u667a\u80fd\u5316\uff0c\u652f\u6301\u4e0d\u540c\u7f51\u7ad9\u7684\u4e2a\u6027\u5316\u9700\u6c42\uff0c\u63d0\u9ad8\u6570\u636e\u63d0\u53d6\u7684\u51c6\u786e\u6027\u3002<\/p>\n<h3>123Proxy\u7684\u670d\u52a1\u6f14\u8fdb<\/h3>\n<p>\u5728\u8fd9\u6837\u7684\u884c\u4e1a\u80cc\u666f\u4e0b\uff0c<strong>123Proxy<\/strong>\u4e5f\u5728\u4e0d\u65ad\u6f14\u8fdb\u5176\u670d\u52a1\uff0c\u4ee5\u6ee1\u8db3\u65e5\u76ca\u589e\u957f\u7684\u5e02\u573a\u9700\u6c42\u3002\u516c\u53f8\u81f4\u529b\u4e8e\u63d0\u4f9b\u591a\u6837\u5316\u7684\u4ee3\u7406\u89e3\u51b3\u65b9\u6848\uff0c\u6db5\u76d6<strong>\u6570\u636e\u91c7\u96c6<\/strong>\u3001\u8de8\u5883\u7535\u5546\u7b49\u5404\u7c7b\u573a\u666f\u3002\u968f\u7740\u884c\u4e1a\u6280\u672f\u7684\u4e0d\u65ad\u63a8\u8fdb\uff0c123Proxy\u5c06\u66f4\u52a0\u6ce8\u91cd\u5bf9\u7528\u6237\u9690\u79c1\u548c\u6570\u636e\u5b89\u5168\u7684\u4fdd\u62a4\u3002<\/p>\n<h3>\u5bf9\u5f00\u53d1\u4eba\u5458\u6280\u80fd\u63d0\u5347\u7684\u5efa\u8bae<\/h3>\n<p>\u9762\u5bf9\u4ee3\u7406\u6280\u672f\u7684\u5feb\u901f\u53d1\u5c55\u548c\u53d8\u5316\uff0c\u5f00\u53d1\u4eba\u5458\u5e94\u4e0d\u65ad\u63d0\u5347\u81ea\u8eab\u7684\u6280\u80fd\uff0c\u4ee5\u9002\u5e94\u65b0\u7684\u5e02\u573a\u9700\u6c42\u3002\u4e00\u65b9\u9762\uff0c\u5efa\u8bae\u5f00\u53d1\u4eba\u5458\u6df1\u5165\u5b66\u4e60<strong>Python<\/strong>\u7b49\u7f16\u7a0b\u8bed\u8a00\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u5904\u7406\u548c\u7f51\u7edc\u4ea4\u4e92\u65b9\u9762\u7684\u5e94\u7528\u80fd\u529b\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u4e86\u89e3\u6700\u65b0\u7684\u6293\u53d6\u5de5\u5177\u548c\u4ee3\u7406\u6280\u672f\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u80fd\u591f\u5e2e\u52a9\u4ed6\u4eec\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\u91c7\u7528\u66f4\u5177\u6548\u7387\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u672c\u6587\u8be6\u89e3\u7684\u6b65\u9aa4\u4e0e\u793a\u4f8b\u4ee3\u7801\uff0c\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728Scrapy\u4e2d\u914d\u7f6e<strong>SOCKS5\u4ee3\u7406<\/strong>\uff0c\u5e76\u8ba4\u8bc6\u5230\u5176\u5728<strong>\u7f51\u9875\u6293\u53d6<\/strong>\u4e2d\u7684\u91cd\u8981\u6027\u3002\u867d\u7136Scrapy\u5bf9SOCKS5\u4ee3\u7406\u7684\u652f\u6301\u76f8\u5bf9\u6709\u9650\uff0c\u4f46\u968f\u7740\u793e\u533a\u5bf9\u8fd9\u4e00\u4e3b\u9898\u7684\u6301\u7eed\u63a2\u7d22\uff0c\u96c6\u6210\u7684\u65b9\u6cd5\u65e5\u76ca\u4e30\u5bcc\uff0c\u5305\u62ec<a href='https:\/\/github.com\/scrapy\/scrapy\/issues\/747'>GitHub\u4e0a\u7684\u8ba8\u8bba<\/a>\u548c\u501f\u52a9<strong>Docker<\/strong>\u5b9e\u73b0\u7684\u9ad8\u7ea7\u8def\u7531\u65b9\u6848\u7b49\uff0c\u5747\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e86\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002\u6b64\u5916\uff0c\u7ed3\u5408<strong>123Proxy<\/strong>\u63d0\u4f9b\u7684\u4f01\u4e1a\u7ea7\u670d\u52a1\uff0c\u7528\u6237\u53ef\u4ee5\u4eab\u53d7\u5230\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684\u4ee3\u7406\u89e3\u51b3\u65b9\u6848\uff0c\u4ece\u800c\u63a8\u52a8\u4ed6\u4eec\u7684\u6570\u636e\u6536\u96c6\u4e0e\u5206\u6790\u5de5\u4f5c\u3002\u901a\u8fc7\u5e94\u7528\u6587\u4e2d\u63d0\u5230\u7684<strong>meta\u53c2\u6570<\/strong>\u548c<strong>\u4ee3\u7406\u4e2d\u95f4\u4ef6<\/strong>\uff0c\u5f00\u53d1\u4eba\u5458\u4e0d\u4ec5\u80fd\u591f\u63d0\u5347\u6293\u53d6\u901f\u5ea6\uff0c\u8fd8\u80fd\u786e\u4fdd<strong>\u7528\u6237\u9690\u79c1<\/strong>\u4e0e<strong>\u7f51\u7edc\u5b89\u5168<\/strong>\u5f97\u4ee5\u4fdd\u969c\u3002\u672a\u6765\uff0c\u968f\u7740\u4ee3\u7406\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\u4e0e\u521b\u65b0\uff0cScrapy\u7684\u4f7f\u7528\u524d\u666f\u5c06\u66f4\u52a0\u5e7f\u9614\uff0c\u4e3a\u5f00\u53d1\u4eba\u5458\u7684\u6280\u80fd\u63d0\u5347\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u673a\u4f1a\u3002<\/p>\n<h2>FAQ<\/h2>\n<p><strong>Q: How can I proxy Scrapy requests with SOCKS5?<\/strong><\/p>\n<p><strong>A: <\/strong>To proxy Scrapy requests with SOCKS5, configure your Scrapy settings by adding the SOCKS5 proxy URL in the <code>DOWNLOADER_MIDDLEWARES<\/code> and ensure the necessary libraries are installed.<\/p>\n<p><strong>Q: What are SOCKS5 proxies and how do they compare to HTTP proxies?<\/strong><\/p>\n<p><strong>A: <\/strong>SOCKS5 proxies are more versatile than HTTP proxies, allowing a variety of protocols and providing better anonymity and performance for web scraping tasks compared to traditional HTTP proxies.<\/p>\n<p><strong>Q: Why should I choose SOCKS5 for web scraping?<\/strong><\/p>\n<p><strong>A: <\/strong>SOCKS5 is preferred for web scraping due to its ability to handle various types of traffic, providing enhanced security, better performance, and more versatile routing capabilities.<\/p>\n<p><strong>Q: Can I use SOCKS5 proxy with authorization in Scrapy?<\/strong><\/p>\n<p><strong>A: <\/strong>While Scrapy does not natively support SOCKS5 proxies with authorization, users can implement a custom middleware to authenticate and connect using the SOCKS5 protocol.<\/p>\n<p><strong>Q: What are common errors when configuring SOCKS5 proxies in Scrapy?<\/strong><\/p>\n<p><strong>A: <\/strong>Common errors include failing to install necessary dependencies, incorrect configuration in the settings file, and network issues preventing connection to the SOCKS5 server.<\/p>\n<p><strong>Q: How can I optimize performance using SOCKS5 proxies in Scrapy?<\/strong><\/p>\n<p><strong>A: <\/strong>Performance can be optimized by implementing techniques like load balancing, retry strategies, and rotating multiple SOCKS5 proxy addresses to distribute the traffic efficiently.<\/p>\n<p><strong>Q: What tools and libraries are recommended for integrating SOCKS5 proxies with Scrapy?<\/strong><\/p>\n<p><strong>A: <\/strong>Recommended tools and libraries include <code>txsocksx<\/code> and <code>scrapy-rotating-proxies<\/code>, which help facilitate easy integration and management of SOCKS5 proxies within the Scrapy framework.<\/p>\n<h2>\u53c2\u8003\u6587\u732e<\/h2>\n<p>1- <a href=\"https:\/\/stackoverflow.com\/questions\/59085184\/how-can-proxy-scrapy-requests-with-socks5\">Stack Overflow<\/a><br \/>2- <a href=\"https:\/\/github.com\/scrapy\/scrapy\/issues\/747\">GitHub<\/a><br \/>3- <a href=\"https:\/\/scrapfly.io\/blog\/what-are-socks5-proxies-in-web-scraping\/\">Scrapfly<\/a><br \/>4- <a href=\"https:\/\/www.zenrows.com\/blog\/scrapy-proxy\">ZenRows<\/a><br \/>5- <a href=\"https:\/\/oxylabs.io\/resources\/integrations\/scrapy-proxy\">Oxylabs<\/a><br \/>6- <a href=\"https:\/\/brookhong.github.io\/2018\/01\/18\/scrapy-with-socks5-proxy.html\">Brook Hong<\/a><br \/>7- <a href=\"https:\/\/123proxy.com\">123Proxy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5982\u4eca\u8fd9\u4e2a\u6570\u636e\u9a71\u52a8\u7684\u65f6\u4ee3\uff0c\u7f51\u7edc\u6293\u53d6\u6210\u4e3a\u4f01\u4e1a\u83b7\u53d6\u7ade\u4e89\u4f18\u52bf\u7684\u5173\u952e\u624b\u6bb5\u4e4b\u4e00\u3002\u7136\u800c\uff0c\u5982\u4f55\u6709\u6548\u96c6\u6210SOCKS5\u4ee3\u7406\u4ee5\u5b9e\u73b0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":22218,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/posts\/22235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/comments?post=22235"}],"version-history":[{"count":0,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/posts\/22235\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/media\/22218"}],"wp:attachment":[{"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/media?parent=22235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/categories?post=22235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/123proxy.cn\/blogs\/wp-json\/wp\/v2\/tags?post=22235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}