{"id":50875,"date":"2024-12-03T10:22:26","date_gmt":"2024-12-03T02:22:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50875\/"},"modified":"2024-12-03T10:22:26","modified_gmt":"2024-12-03T02:22:26","slug":"python-%e7%88%ac%e8%99%ab%e4%bd%bf%e7%94%a8%e4%bb%a3%e7%90%86-ip-%e8%ae%bf%e9%97%ae%e6%b7%98%e5%ae%9d%e6%97%b6%e6%97%a0%e6%b3%95%e7%99%bb%e5%bd%95%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50875\/","title":{"rendered":"Python \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/17328890266749c9c28682c.jpg\" class=\"aligncenter\" title=\"Python \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"Python \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u4f7f\u7528 python \u722c\u866b\u6a21\u62df\u8bbf\u95ee\u6dd8\u5b9d\u65f6\uff0c\u4f7f\u7528\u4ee3\u7406 ip \u540e\u65e0\u6cd5\u767b\u5f55\uff0c\u51fa\u73b0 &#8220;selenium.common.exceptions.invalidcookiedomainexception: message: invalid cookie domain&#8221; \u9519\u8bef\u3002<\/p>\n<p>\u68c0\u67e5\u4ee3\u7801\u540e\u53d1\u73b0\uff0c\u95ee\u9898\u5728\u4e8e get_ip() \u51fd\u6570\u8fd4\u56de\u7684 ip \u5730\u5740\u683c\u5f0f\u4e0d\u6b63\u786e\u3002\u539f\u4ee3\u7801\u4f7f\u7528 str() \u5c06 ip \u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\uff0c\u4f46\u5b9e\u9645\u4e0a\u5b83\u7684\u683c\u5f0f\u5e94\u8be5\u662f `&#8221;{ip}:{port}&#8221;\uff0c\u5176\u4e2d {ip} \u548c {port} \u5206\u522b\u4e3a ip \u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u6b63\u786e\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>def get_ip():\n    with open('.\/ip.text', 'r', encoding='utf8') as f:\n        ip_list = json.loads(f.read())\n\n    num = random.randint(0, len(ip_list))\n    str = \"{0}:{1}\".format(ip_list[num].get('ip'), ip_list[num].get('port'))\n    return str<\/pre>\n<p>\u8fd9\u6837\uff0cget_ip() \u8fd4\u56de\u7684 ip \u5730\u5740\u683c\u5f0f\u5c31\u6b63\u786e\u4e86\uff0c\u4ee3\u7801\u5c31\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\uff0c\u4f7f\u7528\u4ee3\u7406 ip \u767b\u9646\u6dd8\u5b9d\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPython \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u722c\u866b\u4f7f\u7528\u4ee3\u7406 IP \u8bbf\u95ee\u6dd8\u5b9d\u65f6\u65e0\u6cd5\u767b\u5f55\uff0c\u5982\u4f55\u89e3\u51b3\u201cselenium.common.exceptions.InvalidCookieDomainException\u201d\u9519\u8bef\uff1f \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u6587\u7ae0\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ \u5728\u4f7f\u7528 python \u722c\u866b\u6a21\u62df\u8bbf\u95ee\u6dd8\u5b9d\u65f6\uff0c\u4f7f\u7528\u4ee3\u7406 ip \u540e\u65e0\u6cd5\u767b\u5f55\uff0c\u51fa\u73b0 &#8220;selenium.common.exceptions.invalidcookiedomainexception: message: invalid cookie domain&#8221; \u9519\u8bef\u3002 \u68c0\u67e5\u4ee3\u7801\u540e\u53d1\u73b0\uff0c\u95ee\u9898\u5728\u4e8e get_ip() \u51fd\u6570\u8fd4\u56de\u7684 ip \u5730\u5740\u683c\u5f0f\u4e0d\u6b63\u786e\u3002\u539f\u4ee3\u7801\u4f7f\u7528 str() \u5c06 ip \u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\uff0c\u4f46\u5b9e\u9645\u4e0a\u5b83\u7684\u683c\u5f0f\u5e94\u8be5\u662f `&#8221;{ip}:{port}&#8221;\uff0c\u5176\u4e2d {ip} \u548c {port} \u5206\u522b\u4e3a ip \u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002 \u6b63\u786e\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a def get_ip(): with open(&#8216;.\/ip.text&#8217;, &#8216;r&#8217;, encoding=&#8217;utf8&#8242;) as f: ip_list = json.loads(f.read()) num = random.randint(0, len(ip_list)) str = &#8220;{0}:{1}&#8221;.format(ip_list[num].get(&#8216;ip&#8217;), ip_list[num].get(&#8216;port&#8217;)) return str \u8fd9\u6837\uff0cget_ip() [&hellip;]<\/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-50875","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50875","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=50875"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50875\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}