{"id":210,"date":"2019-04-17T23:18:22","date_gmt":"2019-04-17T15:18:22","guid":{"rendered":"http:\/\/www.buyige.net\/?p=210"},"modified":"2019-04-17T23:18:22","modified_gmt":"2019-04-17T15:18:22","slug":"%e5%88%a9%e7%94%a8python%e5%9c%a8%e7%a0%81%e4%b8%8a%e6%b7%98%e5%9c%a8%e7%ba%bf%e8%bd%ac%e6%8d%a2%e6%b7%98%e5%ae%9d%e9%93%be%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/www.buyige.net\/?p=210","title":{"rendered":"\u5229\u7528Python\u5728\u7801\u4e0a\u6dd8\u5728\u7ebf\u8f6c\u6362\u6dd8\u5b9d\u94fe\u63a5"},"content":{"rendered":"\n<p>\u6dd8\u5b9d\u65d7\u4e0b\u7684\u7801\u4e0a\u6dd8\uff0c\u8bf4\u5b9e\u8bdd\u5177\u4f53\u5e72\u5565\u6211\u4e5f\u4e0d\u61c2\uff0c\u603b\u7ed3\u8d77\u6765\u8fd8\u662f\u4e3a\u4e86\u7ebf\u4e0b\u63a8\u5e7f\u3002<\/p>\n\n\n\n<p>\u670b\u53cb\u5728\u505a\u6dd8\u5b9d\uff0c\u6709\u8f6c\u7801\u7684\u9700\u6c42\u3002\u4e4b\u524d\u4ed6\u4e00\u76f4\u662f\u624b\u52a8\u7684\u4e00\u6761\u94fe\u63a5\uff0c\u4e00\u6761\u94fe\u63a5\u7684\u505a\u8f6c\u6362\uff0c\u5de5\u4f5c\u91cf\u5f88\u5927\uff0c\u5f88\u6d6a\u8d39\u65f6\u95f4\u3002\u4e8e\u662f\u9700\u8981\u4e00\u4e2a\u5de5\u5177\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u521a\u597d\u6211\u6700\u8fd1\u4e5f\u662f\u5728\u719f\u6089Python\u8bed\u8a00\uff0c\u8fd9\u4e2a\u7528Python\u7684selenium\u5e93\u5b9e\u73b0\u8d77\u6765\u5e76\u4e0d\u96be\u3002<\/p>\n\n\n\n<p>\u66f4\u6211\u4e0a\u4e00\u4e2a\u535a\u5ba2\u4e2d\u7528\u5230\u7684\u4e1c\u897f\u4e00\u6837\uff0c\u540c\u6837\u662feclipse\u4e0b\u642d\u5efa\u7684Python\u5f00\u53d1\u73af\u5883\uff0c\u5e76\u6ca1\u7528\u7528\u5230pycharm\u3002\u5148\u76f4\u63a5\u4e0a\u4ee3\u7801:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from selenium import webdriver\nfrom time import sleep\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\nimport re\nfrom selenium.webdriver.common.action_chains import ActionChains\nimport urllib\nimport requests\nimport zxing\n#from win32com.client import Dispatch  thunder\n\nchrome_driver='chromedriver.exe'\ndriver = webdriver.Chrome(executable_path= chrome_driver)\n#driver.implicitly_wait(10)\n\nwait=WebDriverWait(driver, 10)\n\ndriver.get(url=\"https:\/\/ma.taobao.com\/\")\n\ndef ocr_zxing(filename):\n    zx = zxing.BarCodeReader()\n    zxdata = zx.decode(filename)\n    print(filename + \":\" + zxdata.parsed)\n\ndef downloadfile(str):    \n    \"\u8f6c\u6362\u7279\u5b9a\u94fe\u63a5\"\n    driver.get(url=\"https:\/\/ma.taobao.com\/web\/create_by_url.htm\")\n    urlle = driver.find_element_by_id('inputUrl')\n    urlle.clear()\n    urlle.send_keys(str)\n\n    try:\n        submit= wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'#form-url > div:nth-child(4) > div > button')))\n        submit.click()\n    except:                        \n        print(\"cant find btnnext\")\n    \n    sleep(3)\n    lename = driver.find_element_by_id(\"inputName\")\n    lename.clear()\n    lename.send_keys(\"\u6d4b\u8bd5\u9898\u76ee\")\n    driver.find_element_by_xpath(\"\/html\/body\/section\/section\/article\/form\/div\/div\/div[3]\/div[2]\/div\/button\").click()\n    sleep(1)\n#     driver.find_element_by_xpath(\"\/html\/body\/section\/section\/article\/div\/div[1]\/div[2]\/div[2]\/div[3]\/div\/div[1]\/div[2]\/a[1]\").click()\n#     input(\"\u4e0b\u8f7d\u540e\u8bf7\u8f93\u5165  1 \")\n\n    img_url = ''\n    findsrc = True\n\n    try:\n        img_url = driver.find_element_by_css_selector(\"body > section > section > article > div > div.data-content.clearfix.step-three > div.success-view > div.sui-form.form-horizontal.pull-left.page-content > div.control-group.mt25 > div > div:nth-child(1) > span > img\").get_attribute(\"src\")                                \n    except:   \n        findsrc = False\n        print(\"cant find btnnext\")\n        # \u4fdd\u5b58\u56fe\u7247\u5230\u6307\u5b9a\u8def\u5f84  \n    if img_url != None and findsrc :\n            #\u4fdd\u5b58\u56fe\u7247\u6570\u636e  \n        data = requests.get(img_url)\n        fileurl = str.split('=')[1] + \".png\"\n        with open(fileurl, 'wb') as f:\n            f.write(data.content)  \n        ocr_zxing(fileurl)\n\n        \nurlstr = ''\n\nwhile (input(\"\u8bf7\u624b\u52a8\u767b\u5f55\uff0c\u767b\u5f55\u5b8c\u6210\u540e\u8bf7\u8f93\u5165  1 \") != '1'):\n    sleep(2)\n    urlstr = input(\"\u8bf7\u8f93\u5165\u8981\u8f6c\u6362\u7684\u94fe\u63a5\uff0c\u9000\u51fa\u76f4\u63a5\u8f93\u5165\\'exit\\'\")\nwhile (urlstr != 'exit') :\n    urlstr = input(\"\u8bf7\u8f93\u5165\u8981\u8f6c\u6362\u7684\u94fe\u63a5\uff0c\u9000\u51fa\u76f4\u63a5\u8f93\u5165\\'exit\\'\")\n    downloadfile(urlstr)<\/code><\/pre>\n\n\n\n<p>\u529f\u80fd\u5176\u5b9e\u4e5f\u662f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u501f\u7528chromedriver.exe\u8c03\u8d77chrome\u6d4f\u89c8\u5668\uff0c\u6253\u5f00 <br><a href=\"https:\/\/ma.taobao.com\/\">https:\/\/ma.taobao.com\/<\/a> \uff08\u7801\u4e0a\u6dd8\u7684\u767b\u5f55\u754c\u9762\uff09\u3002\u8fd9\u91cc\u5c31\u6709\u4e00\u4e2a\u5c0f\u63d2\u66f2\uff0c\u56e0\u4e3a\u6dd8\u5b9d\u505a\u4e86\u76f8\u5e94\u7684\u63aa\u65bd\uff0c\u9632\u6b62\u7c7b\u4f3c\u7684\u811a\u672c\u767b\u5f55\uff0c\u6240\u4ee5\u6709\u201c\u6ed1\u52a8\u767b\u5f55\u201d\u9650\u5236\uff0c\u5f00\u59cb\u6211\u5c1d\u8bd5\u81ea\u5df1\u5199\u811a\u672c\u53bb\u5b9e\u73b0\u8fd9\u4e2a\u6ed1\u52a8\u6548\u679c\uff0c\u4f46\u662f\u591a\u6b21\u5c1d\u8bd5\u5747\u5931\u8d25\u544a\u7ec8\uff0c\u4e8e\u662f\u4e4e\u653e\u5f03\uff0c\u8fd8\u662f\u6709\u70b9\u81ea\u77e5\u4e4b\u660e\u7684\uff0c\u963f\u91cc\u5927\u795e\u4e0d\u662f\u6211\u8fd9\u7b49\u95e8\u5916\u6c49\u80fd\u6311\u6218\u7684\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u5462\uff0c\u4f46\u662f\u6211\u6709\u53d6\u5de7\u7684\u529e\u6cd5\u3002\u5c31\u662f\u6211\u4e0d\u7528\u81ea\u52a8\u767b\u5f55\uff0c\u6211\u7528\u624b\u52a8\u767b\u5f55\uff0c\u6ce8\u610f\u8fd9\u4e2a\u624b\u52a8\u767b\u5f55\u4e0d\u662f\u7b80\u5355\u7684\u624b\u52a8\u767b\u5f55\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8fd9\u4e2a\u7f51\u7ad9\u662f\u5728\u6d4b\u8bd5\u6a21\u5f0f\u4e0b\u624b\u52a8\u4e5f\u767b\u9646\u4e0d\u6765\u7684\uff0c\u4e0d\u76f8\u4fe1\u7684\u53ef\u4ee5\u6d4b\u8bd5\u4e00\u4e0b\u3002\u6548\u679c\u5982\u4e0b\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"824\" src=\"http:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f55-1024x824.png\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f55-1024x824.png 1024w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f55-300x241.png 300w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f55-768x618.png 768w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f55.png 1265w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4f1a\u76f4\u63a5\u62a5\u9519\uff0c\u8fd9\u4e2a\u6211\u89e3\u51b3\u4e0d\u4e86\u3002\u4e0b\u9762\u6ce8\u610f\u89c1\u8bc1\u5947\u8ff9\u7684\u65f6\u5019\u5230\u4e86\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"832\" src=\"http:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f552-1024x832.png\" alt=\"\" class=\"wp-image-217\" srcset=\"https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f552-1024x832.png 1024w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f552-300x244.png 300w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f552-768x624.png 768w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/\u767b\u5f552.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u91cc\u6211\u7684\u5c0f\u6280\u5de7\u5c31\u662f\u6211\u624b\u52a8\u6253\u5f00\u4e00\u4e2a\u6807\u7b7e\u4e5f\uff0c\u626b\u63cf\u767b\u5f55\u6dd8\u5b9d\uff0c\u7136\u540e\u5237\u65b0\u7801\u4e0a\u6dd8\u7684\u754c\u9762\uff0c\u5c31\u53ef\u4ee5\u8fdb\u5165\u4e86\u3002\uff08\u8fd9\u91cc\u662f\u56e0\u4e3a\u6211\u7684\u6c34\u5e73\u6709\u9650\u624d\u6765\u8fd9\u4e00\u51fa\uff0c\u6309\u7406\u8bf4\u4fdd\u5b58cookie\u53ef\u4ee5\u5b9e\u73b0\u767b\u5f55\uff0c\u6211\u95e8\u5916\u6c49\uff0c\u4e0d\u61c2 \u4e5f\u6ca1\u6709\u6d4b\u8bd5\u3002\u5927\u795e\u53ef\u4ee5\u6307\u5bfc\u4e00\u4e0b\uff09<\/p>\n\n\n\n<p>\u8fdb\u5165\u4e4b\u540e\u5728\u7a0b\u5e8f\u7684\u8fd0\u884c\u754c\u9762\u8f93\u51651\uff0c\u5f00\u59cb\u6b63\u5f0f\u8fdb\u5165\u8f6c\u94fe\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65f6\u5019\u5c31\u54df\u610f\u601d\u7684\u4e8b\u60c5\u6765\u4e86\uff0c\u56e0\u4e3a\u6211\u8fd9\u4e2a\u53ea\u662f\u7ed9\u670b\u53cb\u505a\u7684\u5c0f\u5de5\u5177\u6ca1\u6709\u505a\u5230\u5f88\u5b8c\u5584\uff0c\u6240\u6709\u8c03\u8bd5\u7684\u65f6\u5019\u8fd8\u6709\u5f88\u591a\u7ec6\u8282\u95ee\u9898\u9700\u8981\u89e3\u51b3\u3002win10 \u4e0b\u5c06\u4e8c\u7ef4\u7801\u8f6c\u6362\u4e3a\u94fe\u63a5\u7684\u5e93\u8fd0\u884c\u51fa\u9519\uff0c\u8fd9\u4e2a\u6ca1\u89e3\u51b3\u3002\u8fd8\u6709\u5c31\u662f\u56e0\u4e3a\u53ef\u4ee5\u5b9e\u73b0\u8bfb\u53d6\u6587\u4ef6\uff0c\u4fdd\u5b58\u6587\u4ef6\u7684\u65b9\u5f0f\u81ea\u52a8\u5904\u7406\uff0c\u800c\u4e0d\u662f\u624b\u52a8\u7c98\u8d34\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u8fd8\u6709\u4e2a\u5c0f\u7ec6\u8282\uff0c\u5c31\u662f\u5728\u7f16\u8bd1\u5668\u8c03\u8bd5\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u662f\u667a\u80fd\u590d\u5236\u4e00\u6761\uff0c\u8981\u662f\u590d\u5236\u591a\u6761\u4e5f\u4f1a\u53ea\u662f\u8bc6\u522b\u4e00\u6761\uff0c\u4f46\u662f\u6253\u5305\u6210exe\u540e\u518d\u547d\u4ee4\u884c\u4e0b\u53ef\u4ee5\u76f4\u63a5\u590d\u5236\u591a\u884c\u8fd9\u4e2a\u5c31\u5f88\u65b9\u4fbf\uff0c\u4e5f\u5c31\u662f\u591f\u7528\u4e86\u3002\u6548\u679c\u7c7b\u4f3c\u8fd9\u6837<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"http:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-1-1024x582.png\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-1-1024x582.png 1024w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-1-300x171.png 300w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-1-768x437.png 768w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-1.png 1641w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"223\" src=\"http:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image.png\" alt=\"\" class=\"wp-image-219\" srcset=\"https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image.png 733w, https:\/\/www.buyige.net\/wp-content\/uploads\/2019\/04\/image-300x91.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/figure>\n\n\n\n<p>\u6c34\u5e73\u6709\u9650\uff0c\u6709\u613f\u610f\u6307\u5bfc\u7684\u5927\u795e\u53ef\u4ee5\u76f4\u63a5\u8054\u7cfbQQ:371359001<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dd8\u5b9d\u65d7\u4e0b\u7684\u7801\u4e0a\u6dd8\uff0c\u8bf4\u5b9e\u8bdd\u5177\u4f53\u5e72\u5565\u6211\u4e5f\u4e0d\u61c2\uff0c\u603b\u7ed3\u8d77\u6765\u8fd8\u662f\u4e3a\u4e86\u7ebf\u4e0b\u63a8\u5e7f\u3002 \u670b\u53cb\u5728\u505a\u6dd8\u5b9d\uff0c\u6709\u8f6c\u7801\u7684\u9700\u6c42\u3002\u4e4b\u524d\u4ed6\u4e00\u76f4\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyige.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=210"}],"version-history":[{"count":8,"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":222,"href":"https:\/\/www.buyige.net\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions\/222"}],"wp:attachment":[{"href":"https:\/\/www.buyige.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyige.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyige.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}