{"id":1182424,"date":"2025-01-15T19:03:02","date_gmt":"2025-01-15T11:03:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1182424.html"},"modified":"2025-01-15T19:03:05","modified_gmt":"2025-01-15T11:03:05","slug":"python%e7%88%ac%e8%99%ab%e5%a6%82%e4%bd%95%e6%8f%90%e5%8f%96js%e8%8a%82%e7%82%b9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1182424.html","title":{"rendered":"python\u722c\u866b\u5982\u4f55\u63d0\u53d6js\u8282\u70b9"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25130429\/2a1f1118-5a15-4ca9-b06c-f2b00db959a4.webp\" alt=\"python\u722c\u866b\u5982\u4f55\u63d0\u53d6js\u8282\u70b9\" \/><\/p>\n<p><p> <strong>\u8981\u5728 Python \u722c\u866b\u4e2d\u63d0\u53d6 JS \u8282\u70b9\uff0c\u53ef\u4ee5\u4f7f\u7528 Selenium\u3001Pyppeteer\u3001\u6216\u8005 requests-html \u7b49\u5de5\u5177\uff0c\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5904\u7406\u52a8\u6001\u52a0\u8f7d\u7684\u7f51\u9875\u5185\u5bb9\u3002<\/strong> \u4f7f\u7528 Selenium \u662f\u5176\u4e2d\u4e00\u4e2a\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u5b83\u80fd\u591f\u5904\u7406 JavaScript \u6e32\u67d3\u7684\u7f51\u9875\u5e76\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Selenium \u63d0\u53d6 JS \u8282\u70b9\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u548c\u914d\u7f6e Selenium<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5 Selenium<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86 Selenium\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 pip \u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install selenium<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4e0b\u8f7d\u5e76\u914d\u7f6e WebDriver<\/h4>\n<\/p>\n<p><p>Selenium \u9700\u8981 WebDriver \u6765\u4e0e\u6d4f\u89c8\u5668\u8fdb\u884c\u4ea4\u4e92\u3002\u4f60\u9700\u8981\u6839\u636e\u4f60\u4f7f\u7528\u7684\u6d4f\u89c8\u5668\u4e0b\u8f7d\u76f8\u5e94\u7684 WebDriver\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u4f7f\u7528 Chrome \u6d4f\u89c8\u5668\uff0c\u4f60\u9700\u8981\u4e0b\u8f7d ChromeDriver\u3002<\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/\">ChromeDriver<\/a><\/p>\n<\/p>\n<p><p>\u4e0b\u8f7d\u540e\uff0c\u5c06 ChromeDriver \u653e\u5230\u7cfb\u7edf\u7684 PATH \u4e2d\uff0c\u6216\u8005\u5728 Python \u811a\u672c\u4e2d\u6307\u5b9a\u5176\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 Selenium \u63d0\u53d6 JS \u8282\u70b9<\/h3>\n<\/p>\n<p><h4>1\u3001\u521d\u59cb\u5316 WebDriver<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u521d\u59cb\u5316 WebDriver\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<h2><strong>\u521b\u5efa Chrome WebDriver \u5b9e\u4f8b<\/strong><\/h2>\n<p>driver = webdriver.Chrome(executable_path=&#39;\/path\/to\/chromedriver&#39;)<\/p>\n<h2><strong>\u6253\u5f00\u76ee\u6807\u7f51\u9875<\/strong><\/h2>\n<p>driver.get(&#39;https:\/\/example.com&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7b49\u5f85\u9875\u9762\u52a0\u8f7d<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u9875\u9762\u9700\u8981\u4e00\u5b9a\u7684\u65f6\u95f4\u6765\u52a0\u8f7d JavaScript \u5185\u5bb9\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 WebDriverW<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>t \u6765\u7b49\u5f85\u7279\u5b9a\u5143\u7d20\u7684\u52a0\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium.webdriver.common.by import By<\/p>\n<p>from selenium.webdriver.support.ui import WebDriverWait<\/p>\n<p>from selenium.webdriver.support import expected_conditions as EC<\/p>\n<h2><strong>\u7b49\u5f85\u6307\u5b9a\u5143\u7d20\u52a0\u8f7d\u5b8c\u6210<\/strong><\/h2>\n<p>element = WebDriverWait(driver, 10).until(<\/p>\n<p>    EC.presence_of_element_located((By.ID, &quot;element_id&quot;))<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u63d0\u53d6 JS \u8282\u70b9<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u5143\u7d20\u52a0\u8f7d\u5b8c\u6210\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u63d0\u53d6 JS \u8282\u70b9\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9<\/p>\n<p>content = element.text<\/p>\n<h2><strong>\u6216\u8005\u83b7\u53d6\u5143\u7d20\u7684 HTML \u5185\u5bb9<\/strong><\/h2>\n<p>html_content = element.get_attribute(&#39;outerHTML&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5904\u7406\u590d\u6742\u7684 JS \u6e32\u67d3\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5355\u7eaf\u7b49\u5f85\u5143\u7d20\u52a0\u8f7d\u5b8c\u6210\u8fd8\u4e0d\u591f\uff0c\u56e0\u4e3a\u67d0\u4e9b\u5185\u5bb9\u53ef\u80fd\u662f\u901a\u8fc7 AJAX \u5f02\u6b65\u52a0\u8f7d\u7684\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981\u8fdb\u4e00\u6b65\u7b49\u5f85\u6216\u6267\u884c\u7279\u5b9a\u7684 JavaScript \u6765\u786e\u4fdd\u5185\u5bb9\u52a0\u8f7d\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6267\u884c JavaScript<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528 WebDriver \u7684 execute_script \u65b9\u6cd5\u6765\u6267\u884c JavaScript\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6267\u884c JavaScript \u4ee3\u7801<\/p>\n<p>driver.execute_script(&quot;window.scrollTo(0, document.body.scrollHeight);&quot;)<\/p>\n<h2><strong>\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u4ee5\u786e\u4fdd\u5185\u5bb9\u52a0\u8f7d\u5b8c\u6210<\/strong><\/h2>\n<p>import time<\/p>\n<p>time.sleep(2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u63d0\u53d6\u52a8\u6001\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u53ef\u80fd\u9700\u8981\u591a\u6b21\u6eda\u52a8\u9875\u9762\u4ee5\u52a0\u8f7d\u6240\u6709\u52a8\u6001\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u5728\u63d0\u53d6\u65e0\u9650\u6eda\u52a8\u7684\u7f51\u9875\u5185\u5bb9\u65f6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">SCROLL_PAUSE_TIME = 2<\/p>\n<h2><strong>\u83b7\u53d6\u521d\u59cb\u9875\u9762\u9ad8\u5ea6<\/strong><\/h2>\n<p>last_height = driver.execute_script(&quot;return document.body.scrollHeight&quot;)<\/p>\n<p>while True:<\/p>\n<p>    # \u5411\u4e0b\u6eda\u52a8\u9875\u9762<\/p>\n<p>    driver.execute_script(&quot;window.scrollTo(0, document.body.scrollHeight);&quot;)<\/p>\n<p>    # \u7b49\u5f85\u52a0\u8f7d<\/p>\n<p>    time.sleep(SCROLL_PAUSE_TIME)<\/p>\n<p>    # \u83b7\u53d6\u65b0\u7684\u9875\u9762\u9ad8\u5ea6<\/p>\n<p>    new_height = driver.execute_script(&quot;return document.body.scrollHeight&quot;)<\/p>\n<p>    # \u68c0\u67e5\u662f\u5426\u8fbe\u5230\u9875\u9762\u5e95\u90e8<\/p>\n<p>    if new_height == last_height:<\/p>\n<p>        break<\/p>\n<p>    last_height = new_height<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4fdd\u5b58\u548c\u5904\u7406\u63d0\u53d6\u7684\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u63d0\u53d6\u6570\u636e\u540e\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u5176\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u6216\u8005\u8fdb\u4e00\u6b65\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u6570\u636e\u5230\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5c06\u63d0\u53d6\u7684\u6570\u636e\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4f8b\u5982 CSV \u6216 JSON \u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<p>data = {<\/p>\n<p>    &#39;content&#39;: content,<\/p>\n<p>    &#39;html_content&#39;: html_content<\/p>\n<p>}<\/p>\n<h2><strong>\u5c06\u6570\u636e\u4fdd\u5b58\u5230 JSON \u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;data.json&#39;, &#39;w&#39;, encoding=&#39;utf-8&#39;) as f:<\/p>\n<p>    json.dump(data, f, ensure_ascii=False, indent=4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8fdb\u4e00\u6b65\u5904\u7406\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u9700\u8981\u5bf9\u63d0\u53d6\u7684\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u4f8b\u5982\u89e3\u6790 HTML \u5185\u5bb9\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 BeautifulSoup \u6765\u5904\u7406 HTML \u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<h2><strong>\u89e3\u6790 HTML \u5185\u5bb9<\/strong><\/h2>\n<p>soup = BeautifulSoup(html_content, &#39;html.parser&#39;)<\/p>\n<h2><strong>\u63d0\u53d6\u7279\u5b9a\u7684\u8282\u70b9<\/strong><\/h2>\n<p>specific_content = soup.find(&#39;div&#39;, {&#39;class&#39;: &#39;specific-class&#39;}).text<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u793a\u4f8b\uff1a\u63d0\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u8bc4\u8bba<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u4f60\u8981\u63d0\u53d6\u4e00\u4e2a\u52a8\u6001\u52a0\u8f7d\u7684\u7f51\u9875\u4e0a\u7684\u8bc4\u8bba\uff0c\u4f8b\u5982\u67d0\u4e2a\u7535\u5546\u7f51\u7ad9\u7684\u5546\u54c1\u8bc4\u8bba\u3002\u8fd9\u4e9b\u8bc4\u8bba\u53ef\u80fd\u662f\u901a\u8fc7 JavaScript \u52a8\u6001\u52a0\u8f7d\u7684\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521d\u59cb\u5316 WebDriver \u5e76\u6253\u5f00\u7f51\u9875<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>from selenium.webdriver.common.by import By<\/p>\n<p>from selenium.webdriver.support.ui import WebDriverWait<\/p>\n<p>from selenium.webdriver.support import expected_conditions as EC<\/p>\n<p>driver = webdriver.Chrome(executable_path=&#39;\/path\/to\/chromedriver&#39;)<\/p>\n<p>driver.get(&#39;https:\/\/example.com\/product-page&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7b49\u5f85\u8bc4\u8bba\u52a0\u8f7d\u5e76\u63d0\u53d6\u6570\u636e<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7b49\u5f85\u8bc4\u8bba\u533a\u57df\u52a0\u8f7d\u5b8c\u6210<\/p>\n<p>comments_section = WebDriverWait(driver, 10).until(<\/p>\n<p>    EC.presence_of_element_located((By.ID, &quot;comments_section&quot;))<\/p>\n<p>)<\/p>\n<h2><strong>\u83b7\u53d6\u6240\u6709\u8bc4\u8bba<\/strong><\/h2>\n<p>comments = comments_section.find_elements(By.CLASS_NAME, &#39;comment&#39;)<\/p>\n<h2><strong>\u63d0\u53d6\u6bcf\u6761\u8bc4\u8bba\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>comments_data = []<\/p>\n<p>for comment in comments:<\/p>\n<p>    comment_text = comment.find_element(By.CLASS_NAME, &#39;comment_text&#39;).text<\/p>\n<p>    comments_data.append(comment_text)<\/p>\n<h2><strong>\u6253\u5370\u63d0\u53d6\u7684\u8bc4\u8bba<\/strong><\/h2>\n<p>for comment in comments_data:<\/p>\n<p>    print(comment)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4fdd\u5b58\u8bc4\u8bba\u5230\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<h2><strong>\u5c06\u8bc4\u8bba\u4fdd\u5b58\u5230 JSON \u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;comments.json&#39;, &#39;w&#39;, encoding=&#39;utf-8&#39;) as f:<\/p>\n<p>    json.dump(comments_data, f, ensure_ascii=False, indent=4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528 Pyppeteer \u63d0\u53d6 JS \u8282\u70b9<\/h3>\n<\/p>\n<p><p>Pyppeteer \u662f Puppeteer \u7684 Python \u79fb\u690d\u7248\uff0c\u9002\u5408\u5904\u7406\u590d\u6742\u7684 JavaScript \u6e32\u67d3\u5185\u5bb9\u3002\u76f8\u6bd4\u4e8e Selenium\uff0cPyppeteer \u66f4\u52a0\u8f7b\u91cf\u7ea7\u5e76\u4e14\u66f4\u52a0\u7075\u6d3b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5 Pyppeteer<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528 pip \u5b89\u88c5 Pyppeteer\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyppeteer<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 Pyppeteer \u63d0\u53d6 JS \u8282\u70b9<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 Pyppeteer \u63d0\u53d6 JS \u8282\u70b9\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import asyncio<\/p>\n<p>from pyppeteer import launch<\/p>\n<p>async def main():<\/p>\n<p>    browser = await launch()<\/p>\n<p>    page = await browser.newPage()<\/p>\n<p>    await page.goto(&#39;https:\/\/example.com&#39;)<\/p>\n<p>    # \u7b49\u5f85\u7279\u5b9a\u5143\u7d20\u52a0\u8f7d\u5b8c\u6210<\/p>\n<p>    await page.waitForSelector(&#39;#element_id&#39;)<\/p>\n<p>    # \u63d0\u53d6\u5143\u7d20\u7684\u6587\u672c\u5185\u5bb9<\/p>\n<p>    content = await page.evaluate(&#39;document.querySelector(&quot;#element_id&quot;).textContent&#39;)<\/p>\n<p>    print(content)<\/p>\n<p>    await browser.close()<\/p>\n<h2><strong>\u8fd0\u884c\u5f02\u6b65\u4efb\u52a1<\/strong><\/h2>\n<p>asyncio.get_event_loop().run_until_complete(main())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528 requests-html \u63d0\u53d6 JS \u8282\u70b9<\/h3>\n<\/p>\n<p><p>requests-html \u662f\u4e00\u4e2a\u7ed3\u5408\u4e86 requests \u548c PyQuery \u7684\u5e93\uff0c\u80fd\u591f\u8f7b\u677e\u5904\u7406 JavaScript \u6e32\u67d3\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5 requests-html<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528 pip \u5b89\u88c5 requests-html\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests-html<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 requests-html \u63d0\u53d6 JS \u8282\u70b9<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 requests-html \u63d0\u53d6 JS \u8282\u70b9\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from requests_html import HTMLSession<\/p>\n<p>session = HTMLSession()<\/p>\n<p>response = session.get(&#39;https:\/\/example.com&#39;)<\/p>\n<h2><strong>\u6e32\u67d3 JavaScript<\/strong><\/h2>\n<p>response.html.render()<\/p>\n<h2><strong>\u63d0\u53d6\u7279\u5b9a\u5143\u7d20\u7684\u5185\u5bb9<\/strong><\/h2>\n<p>content = response.html.find(&#39;#element_id&#39;, first=True).text<\/p>\n<p>print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728 Python \u722c\u866b\u4e2d\u63d0\u53d6 JS \u8282\u70b9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5176\u4e2d Selenium\u3001Pyppeteer \u548c requests-html \u662f\u5e38\u7528\u7684\u9009\u62e9\u3002\u6bcf\u79cd\u5de5\u5177\u90fd\u6709\u5176\u4f18\u52bf\uff0c\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002<strong>Selenium \u9002\u5408\u5904\u7406\u590d\u6742\u7684\u4ea4\u4e92\u64cd\u4f5c\u3001Pyppeteer \u66f4\u52a0\u8f7b\u91cf\u7ea7\u4e14\u9002\u5408\u5904\u7406\u590d\u6742\u7684 JavaScript \u6e32\u67d3\u5185\u5bb9\u3001requests-html \u5219\u7b80\u5316\u4e86\u5904\u7406 JavaScript \u6e32\u67d3\u7684\u8fc7\u7a0b\u3002<\/strong> \u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u53d6\u52a8\u6001\u52a0\u8f7d\u7684\u7f51\u9875\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u6570\u636e\u5206\u6790\u3001\u6587\u672c\u5904\u7406\u7b49\u591a\u4e2a\u9886\u57df\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u722c\u866b\u4e2d\u8bc6\u522bJavaScript\u751f\u6210\u7684\u5185\u5bb9\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u8fdb\u884c\u722c\u866b\u65f6\uff0c\u8bb8\u591a\u7f51\u7ad9\u7684\u5185\u5bb9\u662f\u901a\u8fc7JavaScript\u52a8\u6001\u751f\u6210\u7684\u3002\u4e3a\u4e86\u63d0\u53d6\u8fd9\u4e9b\u5185\u5bb9\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u50cfSelenium\u8fd9\u6837\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u6a21\u62df\u6d4f\u89c8\u5668\u884c\u4e3a\u5e76\u6267\u884cJavaScript\u4ee3\u7801\uff0c\u4ece\u800c\u83b7\u53d6\u52a8\u6001\u751f\u6210\u7684\u6570\u636e\u3002\u6b64\u5916\uff0c\u4f7f\u7528Pyppeteer\u6216Playwright\u7b49\u73b0\u4ee3\u5e93\u4e5f\u662f\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5b83\u4eec\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5904\u7406JavaScript\u6e32\u67d3\u3002<\/p>\n<p><strong>Python\u722c\u866b\u5982\u4f55\u5904\u7406\u5f02\u6b65\u52a0\u8f7d\u7684JS\u8282\u70b9\uff1f<\/strong><br \/>\u5f02\u6b65\u52a0\u8f7d\u7684JavaScript\u8282\u70b9\u901a\u5e38\u4f1a\u5728\u9875\u9762\u52a0\u8f7d\u540e\u901a\u8fc7AJAX\u8bf7\u6c42\u52a8\u6001\u83b7\u53d6\u6570\u636e\u3002\u4e3a\u4e86\u63d0\u53d6\u8fd9\u4e9b\u5185\u5bb9\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7f51\u7edc\u76d1\u89c6\u5de5\u5177\uff08\u5982Chrome\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff09\u6765\u627e\u5230\u76f8\u5e94\u7684API\u8bf7\u6c42\u3002\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528requests\u5e93\u76f4\u63a5\u8c03\u7528\u8fd9\u4e9bAPI\uff0c\u4ece\u800c\u83b7\u53d6\u6240\u9700\u7684\u6570\u636e\uff0c\u907f\u514d\u4e86\u9700\u8981\u89e3\u6790\u6574\u4e2a\u9875\u9762\u7684\u590d\u6742\u6027\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u63a8\u8350\u7684\u5e93\u53ef\u4ee5\u5e2e\u52a9\u63d0\u53d6JS\u8282\u70b9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6709\u51e0\u4e2a\u5e93\u53ef\u4ee5\u5e2e\u52a9\u60a8\u63d0\u53d6JavaScript\u8282\u70b9\u3002\u9664\u4e86Selenium\u5916\uff0cBeautiful Soup\u548clxml\u53ef\u4ee5\u7528\u6765\u89e3\u6790HTML\u6587\u6863\uff0c\u4f46\u5728\u5904\u7406JavaScript\u751f\u6210\u7684\u5185\u5bb9\u65f6\uff0c\u5b83\u4eec\u7684\u80fd\u529b\u6709\u9650\u3002\u5bf9\u4e8e\u52a8\u6001\u5185\u5bb9\uff0cScrapy\u6846\u67b6\u7ed3\u5408Splash\uff08\u4e00\u4e2a\u6e32\u67d3\u670d\u52a1\uff09\u4e5f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ec4\u5408\uff0c\u80fd\u591f\u6293\u53d6\u590d\u6742\u7684JavaScript\u9875\u9762\u5e76\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728 Python \u722c\u866b\u4e2d\u63d0\u53d6 JS \u8282\u70b9\uff0c\u53ef\u4ee5\u4f7f\u7528 Selenium\u3001Pyppeteer\u3001\u6216\u8005 reques [&hellip;]","protected":false},"author":3,"featured_media":1182431,"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\/1182424"}],"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=1182424"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182424\/revisions"}],"predecessor-version":[{"id":1182436,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1182424\/revisions\/1182436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1182431"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1182424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1182424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1182424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}