{"id":108,"date":"2025-09-24T15:12:09","date_gmt":"2025-09-24T07:12:09","guid":{"rendered":"http:\/\/thebugmuxi.xyz\/?p=108"},"modified":"2025-09-24T15:12:12","modified_gmt":"2025-09-24T07:12:12","slug":"%e5%9f%ba%e4%ba%8epython%e5%92%8cselenium%e9%a2%86%e5%8f%96%e5%be%ae%e8%bd%af%e7%a7%af%e5%88%86","status":"publish","type":"post","link":"https:\/\/www.thebugmuxi.xyz\/index.php\/2025\/09\/24\/%e5%9f%ba%e4%ba%8epython%e5%92%8cselenium%e9%a2%86%e5%8f%96%e5%be%ae%e8%bd%af%e7%a7%af%e5%88%86\/","title":{"rendered":"\u57fa\u4e8epython\u548cSelenium\u9886\u53d6\u5fae\u8f6f\u79ef\u5206"},"content":{"rendered":"\n<p>\u524d\u6bb5\u65f6\u95f4\u6211\u5728GitHub\u4e0a\u5f00\u6e90\u4e86\u4e00\u6b3e\u5fae\u8f6f\u79ef\u5206\u811a\u672c\uff0c\u4f46\u662f\u5bf9\u4e8e\u90e8\u5206\u5c0f\u767d\u7528\u8d77\u6765\u5f88\u6709\u96be\u5ea6\uff0c\u6211\u5c31\u7528\u6700\u8fd1\u5728\u5b66\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u7684Selenium\u5199\u4e86\u4e00\u4e2a\u81ea\u52a8\u5316\u811a\u672c\u6765\u5237\u53d6\u79ef\u5206<\/p>\n\n\n\n<p>\u5fae\u8f6f\u7684 Microsoft Rewards \u8ba1\u5212\u53ef\u4ee5\u901a\u8fc7 Bing \u641c\u7d22\u8d5a\u53d6\u79ef\u5206\uff0c\u79ef\u5206\u53ef\u4ee5\u5151\u6362\u793c\u54c1\u5361\u3001\u6e38\u620f\u7b49\u3002\u6bcf\u5929\u7684\u641c\u7d22\u4efb\u52a1\u4e0d\u591a\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u811a\u672c\u81ea\u52a8\u5b8c\u6210\uff0c\u63d0\u9ad8\u6548\u7387\uff0c\u89e3\u653e\u53cc\u624b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.https:\/\/www.thebugmuxi.xyz\/wp-content\/uploads\/2025\/09\/image-6-1024x775.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"775\" data-original=\"https:\/\/www.https:\/\/www.thebugmuxi.xyz\/wp-content\/uploads\/2025\/09\/image-6-1024x775.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-109\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>\u672c\u6587\u5c06\u624b\u628a\u624b\u6559\u4f60\u5982\u4f55\u90e8\u7f72\u4e00\u4e2a\u81ea\u52a8\u5237\u79ef\u5206\u811a\u672c\uff0c\u5e76\u89e3\u91ca\u5176\u80cc\u540e\u7684\u539f\u7406\u548c\u5b9e\u73b0\u7ec6\u8282\u3002<\/p>\n\n\n\n<p>\u4e00\u3001\u51c6\u5907\u5de5\u4f5c<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5b89\u88c5 Python \u548c\u4f9d\u8d56<br>\u9996\u5148\u4f60\u9700\u8981\u5b89\u88c5 Python\uff08\u63a8\u8350 3.7+\uff09\uff0c\u7136\u540e\u7528 pip \u5b89\u88c5\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5e93 selenium\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5b89\u88c5\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5e93\npip install selenium<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u4e0b\u8f7d Edge \u6d4f\u89c8\u5668\u9a71\u52a8\uff08EdgeDriver\uff09<br>\u8bbf\u95ee \u00a0\u5b98\u65b9 EdgeDriver \u4e0b\u8f7d\u9875\u9762\uff0c\u4e0b\u8f7d\u4e0e\u4f60\u7684 Edge \u6d4f\u89c8\u5668\u7248\u672c\u76f8\u5339\u914d\u7684\u9a71\u52a8\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u89e3\u538b\u540e\uff0c\u5c06 msedgedriver.exe \u653e\u5165\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf PATH \u4e2d\uff1b<\/p>\n\n\n\n<p>\u6216\u8005\u548c\u811a\u672c\u653e\u5230\u540c\u4e00\u9014\u5f84\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.https:\/\/www.thebugmuxi.xyz\/wp-content\/uploads\/2025\/09\/image-8.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"997\" height=\"86\" data-original=\"https:\/\/www.https:\/\/www.thebugmuxi.xyz\/wp-content\/uploads\/2025\/09\/image-8.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-111\"  sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/div><\/figure>\n\n\n\n<p>\u4e8c\u3001\u81ea\u52a8\u5237\u79ef\u5206\u811a\u672c<br>\u4e0b\u9762\u662f\u5b8c\u6574\u7684 Python \u811a\u672c\uff0c\u4f60\u53ea\u9700\u4fdd\u5b58\u4e3a bing_auto_search.py \u5373\u53ef\u3002\u6ce8\u610f\u8981\u548c msedgedriver.exe \u653e\u5230\u540c\u4e00\u4e2a\u76ee\u5f55\u6216\u8005\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\nimport random\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\n\n# --------------------\u914d\u7f6e\u533a\u57df--------------------\nMIN_SEARCH_TIMES = 40 # \u6700\u5c11\u641c\u7d22\u6b21\u6570\nMAX_SEARCH_TIMES = 60  # \u6700\u591a\u641c\u7d22\u6b21\u6570\nWAIT_TIME = (2, 6)     # \u6bcf\u6b21\u641c\u7d22\u540e\u7b49\u5f85\u7684\u65f6\u95f4\u8303\u56f4\uff08\u79d2\uff09\n\nKEYWORDS = &#91;\n    # \u6280\u672f &amp; \u7f16\u7a0b\n    \"best programming languages 2025\", \"python vs javascript\", \"machine learning tutorials\",\n    \"what is cloud computing\", \"how to build a website\", \"C++ smart pointers\", \"Git vs SVN\",\n    \"docker vs virtual machine\", \"REST vs GraphQL\", \"how does blockchain work\", \"WebAssembly tutorial\",\n\n    # ChatGPT &amp; AI\n    \"how ChatGPT works\", \"latest OpenAI news\", \"future of artificial intelligence\", \"AI tools for productivity\",\n    \"ChatGPT for coding\", \"DALL\u00b7E image generation\", \"prompt engineering tips\",\n\n    # \u91d1\u878d &amp; \u6295\u8d44\n    \"Tesla stock news\", \"Bitcoin price prediction\", \"how to invest in ETFs\", \"stock market news today\",\n    \"is gold a good investment\", \"S&amp;P 500 index meaning\", \"cryptocurrency tax rules\",\n\n    # \u5065\u5eb7 &amp; \u751f\u6d3b\u65b9\u5f0f\n    \"healthy breakfast ideas\", \"how to sleep better\", \"how to reduce stress\", \"is coffee healthy\",\n    \"benefits of drinking water\", \"best home workouts\", \"intermittent fasting benefits\",\n\n    # \u5a31\u4e50 &amp; \u70ed\u95e8\u6587\u5316\n    \"Game of Thrones recap\", \"best Netflix shows 2025\", \"funny cat videos\", \"Marvel vs DC\",\n    \"upcoming movies 2025\", \"Oscars best picture winners\", \"top YouTubers 2025\", \"Twitch vs Kick\",\n\n    # \u6559\u80b2 &amp; \u5b66\u4e60\n    \"top universities in the world\", \"best online courses\", \"how to learn English fast\",\n    \"study tips for exams\", \"what is the GRE test\", \"is SAT required in 2025\",\n\n    # \u65c5\u6e38 &amp; \u5730\u7406\n    \"best travel destinations 2025\", \"how to get cheap flights\", \"top 10 cities to live in\",\n    \"weather in Tokyo\", \"hiking trails near me\", \"digital nomad lifestyle\",\n\n    # \u793e\u4f1a\u70ed\u70b9 &amp; \u65b0\u95fb\n    \"Ukraine conflict explained\", \"US presidential election\", \"global warming facts\",\n    \"climate change solutions\", \"latest tech news\", \"AI replacing jobs\", \"privacy concerns with smartphones\",\n\n    # \u5546\u4e1a &amp; \u521b\u4e1a\n    \"how to start a business\", \"make money online\", \"passive income ideas\", \"top e-commerce platforms\",\n    \"dropshipping vs Amazon FBA\", \"remote work trends\", \"freelancing vs full-time job\",\n\n    # \u6e38\u620f &amp; \u7535\u7ade\n    \"best PC games 2025\", \"Valorant tips and tricks\", \"how to get better at Fortnite\",\n    \"Steam summer sale\", \"Nintendo Switch 2 rumors\", \"top esports teams\",\n\n    # \u6742\u9879 &amp; \u8f7b\u677e\u8bdd\u9898\n    \"zodiac sign personality\", \"meaning of dreams\", \"fun trivia questions\", \"weird facts about space\",\n    \"does pineapple belong on pizza\", \"best memes of 2025\", \"how to cook pasta\",\n    \"coffee vs tea\", \"cats vs dogs\", \"funny dad jokes\", \"TikTok trends 2025\"\n]\n\n# -----------------------------------------------\n\noptions = webdriver.EdgeOptions()\noptions.add_argument(\"--start-maximized\")\n\ndriver = webdriver.Edge(options=options)\ndriver.get(\"https:\/\/www.bing.com\")\ntime.sleep(5)  # \u7b49\u4f60\u767b\u5f55\u8d26\u53f7\n\nsuccess_count = 0\nattempt = 0\nmax_attempts = MAX_SEARCH_TIMES + 10  # \u7ed9\u70b9\u5bb9\u9519\n\nwhile success_count &lt; MIN_SEARCH_TIMES and attempt &lt; max_attempts:\n    attempt += 1\n    keyword = random.choice(KEYWORDS)\n    print(f\"&#91;{success_count+1}\/{MIN_SEARCH_TIMES}] Searching: {keyword}\")\n    \n    try:\n        search_box = driver.find_element(By.NAME, \"q\")\n        search_box.clear()\n        search_box.send_keys(keyword)\n        search_box.submit()\n        success_count += 1\n    except Exception as e:\n        print(f\"\u641c\u7d22\u5931\u8d25\uff08\u7b2c {attempt} \u6b21\u5c1d\u8bd5\uff09\uff1a{e}\")\n        driver.get(\"https:\/\/www.bing.com\")\n        time.sleep(1)\n        continue\n\n    time.sleep(random.uniform(*WAIT_TIME))\n    driver.get(\"https:\/\/www.bing.com\")\n\nprint(f\"\\n\u6210\u529f\u641c\u7d22 {success_count} \u6b21\uff0c\u5173\u95ed\u6d4f\u89c8\u5668\u3002\")\ndriver.quit()\n<\/code><\/pre>\n\n\n\n<p>\u4e09\u3001\u5b9e\u73b0\u539f\u7406\u5206\u6790<br>\u8fd9\u4e2a\u81ea\u52a8\u811a\u672c\u80cc\u540e\u7528\u5230\u4e86 Selenium \u6280\u672f\uff0c\u6574\u4f53\u6d41\u7a0b\u662f\uff1a<\/p>\n\n\n\n<p>\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a<br>\u811a\u672c\u901a\u8fc7 Selenium \u6253\u5f00 Edge \u6d4f\u89c8\u5668\uff0c\u5c31\u50cf\u4f60\u624b\u52a8\u70b9\u5f00\u4e00\u6837\uff1b\u7136\u540e\u8bbf\u95ee Bing \u641c\u7d22\u4e3b\u9875\u3002<br>\u4fdd\u6301\u767b\u5f55\u72b6\u6001<br>\u5982\u679c\u4f60\u63d0\u524d\u767b\u5f55\u597d Microsoft \u8d26\u53f7\u5e76\u4fdd\u7559\u4e86 Cookie\uff0c\u811a\u672c\u641c\u7d22\u65f6\u5c31\u4f1a\u81ea\u52a8\u8bb0\u4e3a\u4f60\u7684\u64cd\u4f5c\uff1b<br>\u5426\u5219\u79ef\u5206\u4e0d\u4f1a\u589e\u52a0\u3002<br>\u5faa\u73af\u6a21\u62df\u7528\u6237\u8f93\u5165\u641c\u7d22<br>\u6bcf\u6b21\u4ece\u5173\u952e\u5b57\u5217\u8868\u4e2d\u968f\u673a\u6311\u9009\u4e00\u4e2a\u641c\u7d22\u8bcd\uff1b<br>\u627e\u5230\u641c\u7d22\u6846\uff0c\u8f93\u5165\u5173\u952e\u8bcd\uff0c\u6a21\u62df\u56de\u8f66\uff1b<br>\u7b49\u5f85\u51e0\u79d2\uff0c\u968f\u673a\u6a21\u62df\u201c\u4eba\u64cd\u4f5c\u201d\u7684\u95f4\u9694\uff1b<br>\u7136\u540e\u8fd4\u56de\u9996\u9875\u51c6\u5907\u4e0b\u4e00\u4e2a\u641c\u7d22\u3002<br>\u89e6\u53d1\u79ef\u5206\u7cfb\u7edf\u8bb0\u5f55<br>\u6bcf\u6b21\u641c\u7d22\u90fd\u4f1a\u89e6\u53d1 Bing \u540e\u7aef\u8bb0\u5f55\u884c\u4e3a\uff1b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u79ef\u5206\u7cfb\u7edf\u4f1a\u5728\u540e\u53f0\u589e\u52a0\u5f53\u5929\u7684\u641c\u7d22\u79ef\u5206\uff08PC\u7aef\u6bcf\u65e5\u6700\u591a35\u6b21\uff09<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u6bb5\u65f6\u95f4\u6211\u5728GitHub\u4e0a\u5f00\u6e90\u4e86\u4e00\u6b3e\u5fae\u8f6f\u79ef\u5206\u811a\u672c\uff0c\u4f46\u662f\u5bf9\u4e8e\u90e8\u5206\u5c0f\u767d\u7528\u8d77\u6765\u5f88\u6709\u96be\u5ea6\uff0c\u6211\u5c31\u7528\u6700\u8fd1\u5728\u5b66\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":24,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,10,1],"tags":[24,11,8,12],"class_list":["post-108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-10","category-leam","tag-python","tag-windows","tag-8","tag-12"],"_links":{"self":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions\/112"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/media\/24"}],"wp:attachment":[{"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thebugmuxi.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}