{"id":1124,"date":"2026-07-02T09:53:58","date_gmt":"2026-07-02T01:53:58","guid":{"rendered":"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/selenium-web-scraping-python\/"},"modified":"2026-07-02T09:53:58","modified_gmt":"2026-07-02T01:53:58","slug":"selenium-web-scraping-python","status":"publish","type":"post","link":"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/selenium-web-scraping-python\/","title":{"rendered":"Python + Selenium \u722c\u866b\u5b9e\u6218\u6559\u7a0b\uff1a\u4ece\u5165\u95e8\u5230\u8fdb\u9636"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Selenium \u867d\u7136\u662f\u6d4b\u8bd5\u5de5\u5177\uff0c\u4f46\u5728\u722c\u866b\u9886\u57df\u62e5\u6709\u4e0d\u53ef\u66ff\u4ee3\u7684\u5730\u4f4d\u2014\u2014\u5f53\u4f60\u9700\u8981\u5904\u7406 JavaScript \u52a8\u6001\u6e32\u67d3\u7684\u9875\u9762\u65f6\uff0c\u5b83\u662f\u6700\u53ef\u9760\u7684\u65b9\u6848\u4e4b\u4e00\u3002\u672c\u6587\u5e26\u4f60\u4ece\u96f6\u5f00\u59cb\u7528 Python + Selenium \u91c7\u96c6\u52a8\u6001\u7f51\u9875\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u73af\u5883\u642d\u5efa<\/h2>\n<pre class=\"wp-block-code\"><code>pip install selenium webdriver-manager<\/code><\/pre>\n<p class=\"wp-block-paragraph\">webdriver-manager \u81ea\u52a8\u7ba1\u7406 ChromeDriver\uff0c\u7701\u53bb\u624b\u52a8\u4e0b\u8f7d\u548c\u7248\u672c\u5339\u914d\u7684\u9ebb\u70e6\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u7840\u7528\u6cd5<\/h2>\n<pre class=\"wp-block-code\"><code>from selenium import webdriver\nfrom selenium.webdriver.chrome.service import Service\nfrom webdriver_manager.chrome import ChromeDriverManager\n\ndriver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))\ndriver.get(\"https:\/\/example.com\")\nprint(driver.title)\nprint(driver.page_source)\ndriver.quit()<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u65e0\u5934\u6a21\u5f0f + \u4ee3\u7406<\/h2>\n<pre class=\"wp-block-code\"><code>from selenium.webdriver.chrome.options import Options\n\noptions = Options()\noptions.add_argument(\"--headless\")\noptions.add_argument(\"--proxy-server=http:\/\/user:pass@proxy_ip:port\")\noptions.add_argument(\"--no-sandbox\")\noptions.add_argument(\"--disable-dev-shm-usage\")\n\ndriver = webdriver.Chrome(options=options)<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u7b49\u5f85\u548c\u5b9a\u4f4d\u5143\u7d20<\/h2>\n<pre class=\"wp-block-code\"><code>from selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n\n# \u7b49\u5f85\u5143\u7d20\u51fa\u73b0\nelement = WebDriverWait(driver, 10).until(\n    EC.presence_of_element_located((By.CLASS_NAME, \"content\"))\n)\n\n# \u63d0\u53d6\u6570\u636e\nitems = driver.find_elements(By.CSS_SELECTOR, \".product .price\")\nfor item in items:\n    print(item.text)<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">\u5904\u7406\u53cd\u722c<\/h2>\n<ul class=\"wp-block-list\">\n<li>\u8bbe\u7f6e\u5408\u7406\u7684 User-Agent<\/li>\n<li>\u4f7f\u7528\u968f\u673a\u5ef6\u8fdf\uff083-10 \u79d2\uff09<\/li>\n<li>\u914d\u5408\u4ee3\u7406\u8f6e\u6362<\/li>\n<li>\u6ce8\u5165 JS \u9690\u85cf\u81ea\u52a8\u5316\u75d5\u8ff9<\/li>\n<li>\u5fc5\u8981\u65f6\u5207\u6362\u4e3a\u6709\u5934\u6a21\u5f0f<\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">\u76f8\u5173\u6559\u7a0b<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/scrapy-vs-selenium-vs-beautifulsoup\/\">Scrapy vs Selenium vs BeautifulSoup<\/a><\/li>\n<li><a href=\"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/playwright-vs-puppeteer-vs-selenium\/\">Playwright vs Puppeteer vs Selenium<\/a><\/li>\n<li><a href=\"https:\/\/onehustle.io\/index.php\/2026\/07\/02\/python-web-scraper-tutorial\/\">Python \u722c\u866b\u5165\u95e8\u6559\u7a0b<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Selenium \u867d\u7136\u662f\u6d4b\u8bd5\u5de5\u5177\uff0c\u4f46\u5728\u722c\u866b\u9886\u57df\u62e5\u6709\u4e0d\u53ef\u66ff\u4ee3\u7684\u5730\u4f4d\u2014\u2014\u5f53\u4f60\u9700\u8981\u5904\u7406 JavaScript \u52a8\u6001\u6e32\u67d3\u7684\u9875\u9762\u65f6&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1124","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts\/1124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/comments?post=1124"}],"version-history":[{"count":0,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/posts\/1124\/revisions"}],"wp:attachment":[{"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/media?parent=1124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/categories?post=1124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/onehustle.io\/index.php\/wp-json\/wp\/v2\/tags?post=1124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}