{"id":1104234,"date":"2025-01-08T16:18:54","date_gmt":"2025-01-08T08:18:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1104234.html"},"modified":"2025-01-08T16:18:56","modified_gmt":"2025-01-08T08:18:56","slug":"python3%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e9%aa%8c%e8%af%81%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1104234.html","title":{"rendered":"python3\u5982\u4f55\u5904\u7406\u9a8c\u8bc1\u7801"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065707\/5acad1e4-f657-4cc1-a76e-a57525052e17.webp\" alt=\"python3\u5982\u4f55\u5904\u7406\u9a8c\u8bc1\u7801\" \/><\/p>\n<p><p> <strong>Python3\u5904\u7406\u9a8c\u8bc1\u7801\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\uff1a\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u3001\u6a21\u62df\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801\u3002<\/strong> \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e09\u79cd\u65b9\u6cd5\uff0c\u5e76\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u5b9e\u73b0\u9a8c\u8bc1\u7801\u5904\u7406\uff0c\u5176\u4e2d\u6211\u4eec\u5c06\u7740\u91cd\u8ba8\u8bba\u5982\u4f55\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b<\/p>\n<\/p>\n<p><p>\u56fe\u50cf\u5904\u7406\u662f\u9a8c\u8bc1\u7801\u8bc6\u522b\u4e2d\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u901a\u8fc7Python\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff08\u5982Pillow\u3001OpenCV\uff09\u548cOCR\uff08Optical Character Recognition\uff0c\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u6280\u672f\uff0c\u53ef\u4ee5\u8bc6\u522b\u5e76\u5904\u7406\u5927\u591a\u6570\u9a8c\u8bc1\u7801\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u56fe\u50cf\u5904\u7406\u57fa\u7840<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5904\u7406\u9a8c\u8bc1\u7801\u56fe\u50cf\u3002Pillow\uff08PIL\u7684\u5206\u652f\uff09\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u56fe\u50cf\u3002OpenCV\u662f\u53e6\u4e00\u79cd\u6d41\u884c\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u5982\u56fe\u50cf\u6ee4\u6ce2\u548c\u8fb9\u7f18\u68c0\u6d4b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>import cv2<\/p>\n<h2><strong>\u4f7f\u7528Pillow\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;captcha.png&#39;)<\/p>\n<p>image.show()<\/p>\n<h2><strong>\u4f7f\u7528OpenCV\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>image_cv = cv2.imread(&#39;captcha.png&#39;)<\/p>\n<p>cv2.imshow(&#39;Captcha&#39;, image_cv)<\/p>\n<p>cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.2 \u56fe\u50cf\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u8bc6\u522b\u9a8c\u8bc1\u7801\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u56fe\u50cf\u8fdb\u884c\u9884\u5904\u7406\uff0c\u4ee5\u63d0\u9ad8\u8bc6\u522b\u7684\u51c6\u786e\u6027\u3002\u5e38\u89c1\u7684\u9884\u5904\u7406\u6b65\u9aa4\u5305\u62ec\u7070\u5ea6\u8f6c\u6362\u3001\u4e8c\u503c\u5316\u3001\u566a\u58f0\u53bb\u9664\u548c\u5b57\u7b26\u5206\u5272\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7070\u5ea6\u8f6c\u6362<\/p>\n<p>gray_image = cv2.cvtColor(image_cv, cv2.COLOR_BGR2GRAY)<\/p>\n<h2><strong>\u4e8c\u503c\u5316<\/strong><\/h2>\n<p>_, binary_image = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY)<\/p>\n<h2><strong>\u663e\u793a\u9884\u5904\u7406\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Preprocessed Captcha&#39;, binary_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.3 \u4f7f\u7528OCR\u6280\u672f\u8bc6\u522b\u5b57\u7b26<\/h3>\n<\/p>\n<p><p>Tesseract\u662f\u4e00\u4e2a\u5f00\u6e90\u7684OCR\u5f15\u64ce\uff0c\u53ef\u4ee5\u4e0ePython\u7ed3\u5408\u4f7f\u7528\uff0c\u901a\u8fc7Pytesseract\u5e93\u6765\u5b9e\u73b0\u9a8c\u8bc1\u7801\u8bc6\u522b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pytesseract<\/p>\n<h2><strong>\u4f7f\u7528Pytesseract\u8fdb\u884cOCR\u8bc6\u522b<\/strong><\/h2>\n<p>text = pytesseract.image_to_string(binary_image)<\/p>\n<p>print(f&#39;Recognized Captcha: {text}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.4 \u9a8c\u8bc1\u7801\u5904\u7406\u5b9e\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u548cOCR\u6280\u672f\u8bc6\u522b\u9a8c\u8bc1\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import pytesseract<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>image_path = &#39;captcha.png&#39;<\/p>\n<p>image = Image.open(image_path)<\/p>\n<p>image_cv = cv2.imread(image_path)<\/p>\n<h2><strong>\u56fe\u50cf\u9884\u5904\u7406<\/strong><\/h2>\n<p>gray_image = cv2.cvtColor(image_cv, cv2.COLOR_BGR2GRAY)<\/p>\n<p>_, binary_image = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY)<\/p>\n<h2><strong>\u4f7f\u7528Pytesseract\u8fdb\u884cOCR\u8bc6\u522b<\/strong><\/h2>\n<p>text = pytesseract.image_to_string(binary_image)<\/p>\n<p>print(f&#39;Recognized Captcha: {text}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u56fe\u50cf\u5904\u7406\u6280\u672f\uff0c\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u4e5f\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u8fd9\u4e9b\u670d\u52a1\u901a\u5e38\u63d0\u4f9bAPI\u63a5\u53e3\uff0c\u5141\u8bb8\u6211\u4eec\u4e0a\u4f20\u9a8c\u8bc1\u7801\u56fe\u50cf\uff0c\u5e76\u8fd4\u56de\u8bc6\u522b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u9009\u62e9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1<\/h3>\n<\/p>\n<p><p>\u5e02\u9762\u4e0a\u6709\u8bb8\u591a\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u53ef\u4f9b\u9009\u62e9\uff0c\u5982\u8d85\u7ea7\u9e70\u3001\u6253\u7801\u5154\u7b49\u3002\u9009\u62e9\u4e00\u4e2a\u53ef\u9760\u7684\u670d\u52a1\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u9a8c\u8bc1\u7801\u8bc6\u522b\u7684\u51c6\u786e\u6027\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>2.2 \u96c6\u6210\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1<\/h3>\n<\/p>\n<p><p>\u4ee5\u8d85\u7ea7\u9e70\u4e3a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u96c6\u6210\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u8d85\u7ea7\u9e70API\u914d\u7f6e<\/strong><\/h2>\n<p>api_url = &#39;http:\/\/upload.chaojiying.net\/Upload\/Processing.php&#39;<\/p>\n<p>username = &#39;your_username&#39;<\/p>\n<p>password = &#39;your_password&#39;<\/p>\n<p>soft_id = &#39;your_soft_id&#39;<\/p>\n<p>captcha_type = &#39;1902&#39;  # \u9a8c\u8bc1\u7801\u7c7b\u578b<\/p>\n<h2><strong>\u8bfb\u53d6\u9a8c\u8bc1\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>image_path = &#39;captcha.png&#39;<\/p>\n<p>with open(image_path, &#39;rb&#39;) as f:<\/p>\n<p>    image_data = f.read()<\/p>\n<h2><strong>\u53d1\u9001\u8bc6\u522b\u8bf7\u6c42<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;user&#39;: username,<\/p>\n<p>    &#39;pass2&#39;: password,<\/p>\n<p>    &#39;softid&#39;: soft_id,<\/p>\n<p>    &#39;codetype&#39;: captcha_type,<\/p>\n<p>}<\/p>\n<p>files = {&#39;userfile&#39;: (&#39;captcha.png&#39;, image_data)}<\/p>\n<p>response = requests.post(api_url, data=data, files=files)<\/p>\n<p>result = response.json()<\/p>\n<h2><strong>\u8f93\u51fa\u8bc6\u522b\u7ed3\u679c<\/strong><\/h2>\n<p>if result[&#39;err_no&#39;] == 0:<\/p>\n<p>    print(f&#39;Recognized Captcha: {result[&quot;pic_str&quot;]}&#39;)<\/p>\n<p>else:<\/p>\n<p>    print(f&#39;Error: {result[&quot;err_str&quot;]}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u6a21\u62df\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9a8c\u8bc1\u7801\u53ef\u80fd\u8fc7\u4e8e\u590d\u6742\u6216\u7ecf\u8fc7\u9632\u8303\u6280\u672f\u5904\u7406\uff0c\u4f7f\u5f97\u81ea\u52a8\u8bc6\u522b\u53d8\u5f97\u56f0\u96be\u3002\u8fd9\u65f6\uff0c\u53ef\u4ee5\u6a21\u62df\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801\u7684\u65b9\u5f0f\u6765\u7ed5\u8fc7\u9a8c\u8bc1\u7801\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u4f7f\u7528Selenium\u6a21\u62df\u624b\u52a8\u8f93\u5165<\/h3>\n<\/p>\n<p><p>Selenium\u662f\u4e00\u4e2a\u5f3a\u5927\u7684Web\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u64cd\u4f5c\uff0c\u5305\u62ec\u8f93\u5165\u9a8c\u8bc1\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.common.keys import Keys<\/p>\n<h2><strong>\u542f\u52a8\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver = webdriver.Chrome()<\/p>\n<h2><strong>\u6253\u5f00\u76ee\u6807\u9875\u9762<\/strong><\/h2>\n<p>driver.get(&#39;https:\/\/example.com&#39;)<\/p>\n<h2><strong>\u5b9a\u4f4d\u9a8c\u8bc1\u7801\u8f93\u5165\u6846<\/strong><\/h2>\n<p>captcha_input = driver.find_element_by_id(&#39;captcha_input&#39;)<\/p>\n<h2><strong>\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801<\/strong><\/h2>\n<p>captcha_text = input(&#39;Please enter the captcha: &#39;)<\/p>\n<p>captcha_input.send_keys(captcha_text)<\/p>\n<h2><strong>\u63d0\u4ea4\u8868\u5355<\/strong><\/h2>\n<p>submit_button = driver.find_element_by_id(&#39;submit_button&#39;)<\/p>\n<p>submit_button.click()<\/p>\n<h2><strong>\u5173\u95ed\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2 \u81ea\u52a8\u5316\u6d41\u7a0b<\/h3>\n<\/p>\n<p><p>\u7ed3\u5408\u56fe\u50cf\u5904\u7406\u548c\u624b\u52a8\u8f93\u5165\uff0c\u53ef\u4ee5\u5b9e\u73b0\u534a\u81ea\u52a8\u5316\u7684\u9a8c\u8bc1\u7801\u5904\u7406\u6d41\u7a0b\u3002\u4f8b\u5982\uff0c\u9996\u5148\u4f7f\u7528OCR\u6280\u672f\u5c1d\u8bd5\u8bc6\u522b\u9a8c\u8bc1\u7801\uff0c\u5982\u679c\u8bc6\u522b\u5931\u8d25\uff0c\u5219\u63d0\u793a\u7528\u6237\u624b\u52a8\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.common.keys import Keys<\/p>\n<p>import cv2<\/p>\n<p>import pytesseract<\/p>\n<p>from PIL import Image<\/p>\n<h2><strong>\u542f\u52a8\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver = webdriver.Chrome()<\/p>\n<h2><strong>\u6253\u5f00\u76ee\u6807\u9875\u9762<\/strong><\/h2>\n<p>driver.get(&#39;https:\/\/example.com&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u9a8c\u8bc1\u7801\u56fe\u50cf<\/strong><\/h2>\n<p>captcha_image = driver.find_element_by_id(&#39;captcha_image&#39;)<\/p>\n<p>captcha_image.screenshot(&#39;captcha.png&#39;)<\/p>\n<h2><strong>\u56fe\u50cf\u9884\u5904\u7406\u548cOCR\u8bc6\u522b<\/strong><\/h2>\n<p>image_path = &#39;captcha.png&#39;<\/p>\n<p>image = Image.open(image_path)<\/p>\n<p>image_cv = cv2.imread(image_path)<\/p>\n<p>gray_image = cv2.cvtColor(image_cv, cv2.COLOR_BGR2GRAY)<\/p>\n<p>_, binary_image = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY)<\/p>\n<p>text = pytesseract.image_to_string(binary_image)<\/p>\n<h2><strong>\u9a8c\u8bc1\u7801\u8f93\u5165<\/strong><\/h2>\n<p>captcha_input = driver.find_element_by_id(&#39;captcha_input&#39;)<\/p>\n<p>if text.strip():<\/p>\n<p>    captcha_input.send_keys(text.strip())<\/p>\n<p>else:<\/p>\n<p>    captcha_text = input(&#39;Please enter the captcha: &#39;)<\/p>\n<p>    captcha_input.send_keys(captcha_text)<\/p>\n<h2><strong>\u63d0\u4ea4\u8868\u5355<\/strong><\/h2>\n<p>submit_button = driver.find_element_by_id(&#39;submit_button&#39;)<\/p>\n<p>submit_button.click()<\/p>\n<h2><strong>\u5173\u95ed\u6d4f\u89c8\u5668<\/strong><\/h2>\n<p>driver.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u603b\u7ed3\uff1a<\/p>\n<\/p>\n<p><p>\u5904\u7406\u9a8c\u8bc1\u7801\u662f\u81ea\u52a8\u5316\u6d4b\u8bd5\u548c\u722c\u866b\u5f00\u53d1\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u73af\u8282\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e09\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u3001\u6a21\u62df\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u5177\u4f53\u9009\u62e9\u53d6\u51b3\u4e8e\u5b9e\u9645\u9700\u6c42\u548c\u9a8c\u8bc1\u7801\u7684\u590d\u6742\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u9884\u5904\u7406\u548cOCR\u6280\u672f\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u8bc6\u522b\u5927\u591a\u6570\u9a8c\u8bc1\u7801\u3002\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u53ef\u4ee5\u5feb\u901f\u83b7\u5f97\u9ad8\u51c6\u786e\u7387\u7684\u8bc6\u522b\u7ed3\u679c\uff0c\u4f46\u9700\u8981\u652f\u4ed8\u4e00\u5b9a\u8d39\u7528\u3002\u6a21\u62df\u624b\u52a8\u8f93\u5165\u9a8c\u8bc1\u7801\u9002\u7528\u4e8e\u590d\u6742\u9a8c\u8bc1\u7801\uff0c\u901a\u8fc7\u7ed3\u5408\u81ea\u52a8\u5316\u6d41\u7a0b\u548c\u4eba\u5de5\u8f93\u5165\uff0c\u53ef\u4ee5\u5b9e\u73b0\u534a\u81ea\u52a8\u5316\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u5173\u952e\u5728\u4e8e\u4e0d\u65ad\u4f18\u5316\u548c\u8c03\u6574\uff0c\u4ee5\u63d0\u9ad8\u9a8c\u8bc1\u7801\u8bc6\u522b\u7684\u51c6\u786e\u6027\u548c\u6548\u7387\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u5e76\u7ed3\u5408\u591a\u79cd\u6280\u672f\u624b\u6bb5\uff0c\u8fbe\u5230\u6700\u4f18\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python3\u8bc6\u522b\u56fe\u7247\u9a8c\u8bc1\u7801\uff1f<\/strong><br \/>\u5728Python3\u4e2d\uff0c\u8bc6\u522b\u56fe\u7247\u9a8c\u8bc1\u7801\u901a\u5e38\u53ef\u4ee5\u501f\u52a9OCR\uff08\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u6280\u672f\u6765\u5b9e\u73b0\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ecPillow\uff08\u7528\u4e8e\u56fe\u50cf\u5904\u7406\uff09\u548cTesseract-OCR\uff08\u7528\u4e8e\u5b57\u7b26\u8bc6\u522b\uff09\u3002\u9996\u5148\uff0c\u4f7f\u7528Pillow\u5e93\u6253\u5f00\u5e76\u9884\u5904\u7406\u9a8c\u8bc1\u7801\u56fe\u50cf\uff0c\u5982\u8c03\u6574\u5927\u5c0f\u548c\u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u3002\u63a5\u7740\uff0c\u5229\u7528Tesseract\u5e93\u63d0\u53d6\u56fe\u50cf\u4e2d\u7684\u6587\u5b57\u3002\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5\u76f8\u5e94\u5e93\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e\u548c\u914d\u7f6e\u3002<\/p>\n<p><strong>\u5728Python3\u4e2d\uff0c\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5904\u7406\u9a8c\u8bc1\u7801\uff1f<\/strong><br \/>\u5904\u7406\u9a8c\u8bc1\u7801\u7684\u5e38\u7528\u5e93\u5305\u62ecPillow\u3001OpenCV\u3001Tesseract\u548ccaptcha\u3002Pillow\u548cOpenCV\u4e3b\u8981\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u548c\u589e\u5f3a\uff0c\u5e2e\u52a9\u63d0\u9ad8\u9a8c\u8bc1\u7801\u8bc6\u522b\u7684\u51c6\u786e\u7387\u3002Tesseract\u662f\u4e00\u4e2a\u5f3a\u5927\u7684OCR\u5de5\u5177\uff0c\u53ef\u4ee5\u8bc6\u522b\u56fe\u50cf\u4e2d\u7684\u6587\u672c\u3002captcha\u5e93\u5219\u53ef\u4ee5\u751f\u6210\u7b80\u5355\u7684\u9a8c\u8bc1\u7801\uff0c\u4f9b\u7528\u6237\u8fdb\u884c\u6d4b\u8bd5\u548c\u5b66\u4e60\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u9ad8Python3\u5904\u7406\u9a8c\u8bc1\u7801\u7684\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u63d0\u9ad8\u9a8c\u8bc1\u7801\u8bc6\u522b\u7684\u51c6\u786e\u6027\u53ef\u4ee5\u4ece\u591a\u4e2a\u65b9\u9762\u5165\u624b\u3002\u9996\u5148\uff0c\u786e\u4fdd\u56fe\u50cf\u9884\u5904\u7406\u5f97\u5f53\uff0c\u4f8b\u5982\u53bb\u566a\u58f0\u3001\u4e8c\u503c\u5316\u548c\u8c03\u6574\u5bf9\u6bd4\u5ea6\u3002\u5176\u6b21\uff0c\u9009\u62e9\u5408\u9002\u7684OCR\u5f15\u64ce\u5e76\u8fdb\u884c\u8bad\u7ec3\uff0c\u4ee5\u9002\u5e94\u7279\u5b9a\u7c7b\u578b\u7684\u9a8c\u8bc1\u7801\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\uff08\u5982CNN\uff09\u6765\u6784\u5efa\u81ea\u5b9a\u4e49\u7684\u9a8c\u8bc1\u7801\u8bc6\u522b\u5668\uff0c\u80fd\u663e\u8457\u63d0\u9ad8\u8bc6\u522b\u7387\u3002\u4e0d\u65ad\u5730\u4f18\u5316\u548c\u6d4b\u8bd5\u7b97\u6cd5\u4e5f\u662f\u63d0\u5347\u51c6\u786e\u6027\u7684\u5173\u952e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python3\u5904\u7406\u9a8c\u8bc1\u7801\u7684\u5e38\u7528\u65b9\u6cd5\u5305\u62ec\uff1a\u5229\u7528\u56fe\u50cf\u5904\u7406\u6280\u672f\u8fdb\u884c\u9a8c\u8bc1\u7801\u8bc6\u522b\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u9a8c\u8bc1\u7801\u8bc6\u522b\u670d\u52a1\u3001\u6a21\u62df\u624b\u52a8\u8f93\u5165 [&hellip;]","protected":false},"author":3,"featured_media":1104237,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1104234"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1104234"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1104234\/revisions"}],"predecessor-version":[{"id":1104241,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1104234\/revisions\/1104241"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1104237"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1104234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1104234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1104234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}