{"id":1130989,"date":"2025-01-08T20:44:54","date_gmt":"2025-01-08T12:44:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1130989.html"},"modified":"2025-01-08T20:44:58","modified_gmt":"2025-01-08T12:44:58","slug":"python%e8%87%aa%e5%8a%a8%e5%8c%96%e5%a6%82%e4%bd%95%e5%8f%aa%e7%99%bb%e5%bd%95%e4%b8%80%e6%ac%a1","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1130989.html","title":{"rendered":"python\u81ea\u52a8\u5316\u5982\u4f55\u53ea\u767b\u5f55\u4e00\u6b21"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100905\/002de5af-f396-48e8-aa71-8e2c5be2d2cf.webp\" alt=\"python\u81ea\u52a8\u5316\u5982\u4f55\u53ea\u767b\u5f55\u4e00\u6b21\" \/><\/p>\n<p><p> <strong>Python \u81ea\u52a8\u5316\u5982\u4f55\u53ea\u767b\u5f55\u4e00\u6b21\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c Python \u81ea\u52a8\u5316\u4efb\u52a1\u65f6\uff0c<strong>\u4f7f\u7528\u6301\u4e45\u5316\u4f1a\u8bdd\u3001\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong> \u662f\u786e\u4fdd\u53ea\u767b\u5f55\u4e00\u6b21\u7684\u91cd\u8981\u65b9\u6cd5\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u6301\u4e45\u5316\u4f1a\u8bdd\u662f\u6700\u4e3a\u76f4\u63a5\u548c\u6709\u6548\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u6301\u4e45\u5316\u4f1a\u8bdd\uff0c\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u4f1a\u8bdd\u4e2d\u4fdd\u6301\u767b\u5f55\u72b6\u6001\uff0c\u907f\u514d\u91cd\u590d\u767b\u5f55\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p><strong>\u6301\u4e45\u5316\u4f1a\u8bdd<\/strong> \u662f\u6307\u5728\u6574\u4e2a\u81ea\u52a8\u5316\u4efb\u52a1\u671f\u95f4\u4fdd\u6301\u4e00\u4e2a\u6301\u7eed\u7684\u4f1a\u8bdd\u8fde\u63a5\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u6bcf\u6b21\u8bf7\u6c42\u65f6\u90fd\u9700\u8981\u91cd\u65b0\u767b\u5f55\u3002\u8fd9\u901a\u5e38\u901a\u8fc7\u4f7f\u7528 <code>requests<\/code> \u5e93\u4e2d\u7684 <code>Session<\/code> \u5bf9\u8c61\u6765\u5b9e\u73b0\u3002<code>Session<\/code> \u5bf9\u8c61\u5141\u8bb8\u4f60\u5728\u591a\u4e2a\u8bf7\u6c42\u4e4b\u95f4\u4fdd\u6301\u4e00\u4e9b\u53c2\u6570\uff0c\u6bd4\u5982 cookies \u548c headers\uff0c\u4ece\u800c\u5b9e\u73b0\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\u3002<\/p>\n<\/p>\n<p><p>\u4e0b\u9762\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u5728 Python \u81ea\u52a8\u5316\u4e2d\u53ea\u767b\u5f55\u4e00\u6b21\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u6301\u4e45\u5316\u4f1a\u8bdd<\/h2>\n<\/p>\n<p><h3>\u4f7f\u7528 requests \u5e93\u7684 Session \u5bf9\u8c61<\/h3>\n<\/p>\n<p><p><code>requests<\/code> \u5e93\u662f Python \u4e2d\u7528\u4e8e\u53d1\u9001 HTTP \u8bf7\u6c42\u7684\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a <code>Session<\/code> \u5bf9\u8c61\uff0c\u53ef\u4ee5\u5728\u591a\u4e2a\u8bf7\u6c42\u4e4b\u95f4\u5171\u4eab\u72b6\u6001\u4fe1\u606f\uff0c\u6bd4\u5982 cookies \u548c headers\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u6301\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a Session \u5bf9\u8c61<\/strong><\/h2>\n<p>session = requests.Session()<\/p>\n<h2><strong>\u4f7f\u7528 session \u5bf9\u8c61\u8fdb\u884c\u767b\u5f55<\/strong><\/h2>\n<p>login_url = &quot;https:\/\/example.com\/login&quot;<\/p>\n<p>login_data = {<\/p>\n<p>    &quot;username&quot;: &quot;your_username&quot;,<\/p>\n<p>    &quot;password&quot;: &quot;your_password&quot;<\/p>\n<p>}<\/p>\n<p>response = session.post(login_url, data=login_data)<\/p>\n<h2><strong>\u68c0\u67e5\u767b\u5f55\u662f\u5426\u6210\u529f<\/strong><\/h2>\n<p>if response.ok:<\/p>\n<p>    print(&quot;\u767b\u5f55\u6210\u529f&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u767b\u5f55\u5931\u8d25&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u540c\u4e00\u4e2a session \u5bf9\u8c61\u8fdb\u884c\u5176\u4ed6\u8bf7\u6c42<\/strong><\/h2>\n<p>profile_url = &quot;https:\/\/example.com\/profile&quot;<\/p>\n<p>profile_response = session.get(profile_url)<\/p>\n<p>print(profile_response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ea\u9700\u8981\u767b\u5f55\u4e00\u6b21\uff0c\u7136\u540e\u53ef\u4ee5\u5728\u6574\u4e2a\u4f1a\u8bdd\u671f\u95f4\u4fdd\u6301\u767b\u5f55\u72b6\u6001\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528 cookie \u4fdd\u5b58\u767b\u5f55\u72b6\u6001<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u4fdd\u5b58\u767b\u5f55\u72b6\u6001\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u5728\u91cd\u65b0\u542f\u52a8\u811a\u672c\u65f6\u6062\u590d\u4f1a\u8bdd\u3002\u53ef\u4ee5\u4f7f\u7528 <code>requests<\/code> \u5e93\u548c <code>pickle<\/code> \u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>import pickle<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a Session \u5bf9\u8c61<\/strong><\/h2>\n<p>session = requests.Session()<\/p>\n<h2><strong>\u5c1d\u8bd5\u4ece\u6587\u4ef6\u4e2d\u52a0\u8f7d cookies<\/strong><\/h2>\n<p>try:<\/p>\n<p>    with open(&quot;cookies.pkl&quot;, &quot;rb&quot;) as f:<\/p>\n<p>        session.cookies.update(pickle.load(f))<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    pass<\/p>\n<h2><strong>\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u767b\u5f55<\/strong><\/h2>\n<p>check_login_url = &quot;https:\/\/example.com\/check_login&quot;<\/p>\n<p>response = session.get(check_login_url)<\/p>\n<p>if not response.ok:<\/p>\n<p>    # \u5982\u679c\u6ca1\u6709\u767b\u5f55\uff0c\u5219\u8fdb\u884c\u767b\u5f55<\/p>\n<p>    login_url = &quot;https:\/\/example.com\/login&quot;<\/p>\n<p>    login_data = {<\/p>\n<p>        &quot;username&quot;: &quot;your_username&quot;,<\/p>\n<p>        &quot;password&quot;: &quot;your_password&quot;<\/p>\n<p>    }<\/p>\n<p>    response = session.post(login_url, data=login_data)<\/p>\n<p>    if response.ok:<\/p>\n<p>        # \u4fdd\u5b58 cookies \u5230\u6587\u4ef6<\/p>\n<p>        with open(&quot;cookies.pkl&quot;, &quot;wb&quot;) as f:<\/p>\n<p>            pickle.dump(session.cookies, f)<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;\u767b\u5f55\u5931\u8d25&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u5df2\u7ecf\u767b\u5f55&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u540c\u4e00\u4e2a session \u5bf9\u8c61\u8fdb\u884c\u5176\u4ed6\u8bf7\u6c42<\/strong><\/h2>\n<p>profile_url = &quot;https:\/\/example.com\/profile&quot;<\/p>\n<p>profile_response = session.get(profile_url)<\/p>\n<p>print(profile_response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u811a\u672c\u91cd\u65b0\u542f\u52a8\u65f6\u6062\u590d\u4f1a\u8bdd\uff0c\u907f\u514d\u6bcf\u6b21\u90fd\u9700\u8981\u91cd\u65b0\u767b\u5f55\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c<\/h2>\n<\/p>\n<p><h3>\u4ec0\u4e48\u662f\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c<\/h3>\n<\/p>\n<p><p>\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\uff08Authentication Token\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u9a8c\u8bc1\u7528\u6237\u8eab\u4efd\u7684\u5b89\u5168\u51ed\u8bc1\u3002\u901a\u5e38\u5728\u7528\u6237\u6210\u529f\u767b\u5f55\u540e\uff0c\u670d\u52a1\u5668\u4f1a\u751f\u6210\u4e00\u4e2a\u4ee4\u724c\uff0c\u5e76\u5c06\u5176\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5ba2\u6237\u7aef\u5728\u540e\u7eed\u7684\u8bf7\u6c42\u4e2d\u643a\u5e26\u8fd9\u4e2a\u4ee4\u724c\uff0c\u4ee5\u8bc1\u660e\u81ea\u5df1\u7684\u8eab\u4efd\u3002<\/p>\n<\/p>\n<p><h3>\u5982\u4f55\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c<\/h3>\n<\/p>\n<p><p>\u5728 Python \u81ea\u52a8\u5316\u4efb\u52a1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u767b\u5f55\u540e\u83b7\u53d6\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\uff0c\u5e76\u5728\u540e\u7eed\u8bf7\u6c42\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u4ee4\u724c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>\u767b\u5f55\u5e76\u83b7\u53d6\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c<\/strong><\/h2>\n<p>login_url = &quot;https:\/\/example.com\/api\/login&quot;<\/p>\n<p>login_data = {<\/p>\n<p>    &quot;username&quot;: &quot;your_username&quot;,<\/p>\n<p>    &quot;password&quot;: &quot;your_password&quot;<\/p>\n<p>}<\/p>\n<p>response = requests.post(login_url, json=login_data)<\/p>\n<p>response_data = response.json()<\/p>\n<p>auth_token = response_data[&quot;token&quot;]<\/p>\n<h2><strong>\u5728\u540e\u7eed\u8bf7\u6c42\u4e2d\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c<\/strong><\/h2>\n<p>headers = {<\/p>\n<p>    &quot;Authorization&quot;: f&quot;Bearer {auth_token}&quot;<\/p>\n<p>}<\/p>\n<p>profile_url = &quot;https:\/\/example.com\/api\/profile&quot;<\/p>\n<p>profile_response = requests.get(profile_url, headers=headers)<\/p>\n<p>print(profile_response.json())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6574\u4e2a\u4f1a\u8bdd\u671f\u95f4\u4f7f\u7528\u540c\u4e00\u4e2a\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\uff0c\u907f\u514d\u91cd\u590d\u767b\u5f55\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h2>\n<\/p>\n<p><h3>Selenium<\/h3>\n<\/p>\n<p><p>Selenium \u662f\u4e00\u4e2a\u7528\u4e8e Web \u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u7684\u5f3a\u5927\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e0a\u7684\u64cd\u4f5c\uff0c\u5305\u62ec\u767b\u5f55\u7f51\u7ad9\u3002\u5728\u4f7f\u7528 Selenium \u8fdb\u884c\u81ea\u52a8\u5316\u4efb\u52a1\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fdd\u5b58\u548c\u52a0\u8f7d\u6d4f\u89c8\u5668\u7684 cookies \u6765\u4fdd\u6301\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>import pickle<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6d4f\u89c8\u5668\u5b9e\u4f8b<\/strong><\/h2>\n<p>driver = webdriver.Chrome()<\/p>\n<h2><strong>\u5c1d\u8bd5\u4ece\u6587\u4ef6\u4e2d\u52a0\u8f7d cookies<\/strong><\/h2>\n<p>try:<\/p>\n<p>    with open(&quot;cookies.pkl&quot;, &quot;rb&quot;) as f:<\/p>\n<p>        cookies = pickle.load(f)<\/p>\n<p>        for cookie in cookies:<\/p>\n<p>            driver.add_cookie(cookie)<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    pass<\/p>\n<h2><strong>\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u767b\u5f55<\/strong><\/h2>\n<p>driver.get(&quot;https:\/\/example.com\/check_login&quot;)<\/p>\n<p>if &quot;Login&quot; in driver.title:<\/p>\n<p>    # \u5982\u679c\u6ca1\u6709\u767b\u5f55\uff0c\u5219\u8fdb\u884c\u767b\u5f55<\/p>\n<p>    driver.get(&quot;https:\/\/example.com\/login&quot;)<\/p>\n<p>    driver.find_element_by_name(&quot;username&quot;).send_keys(&quot;your_username&quot;)<\/p>\n<p>    driver.find_element_by_name(&quot;password&quot;).send_keys(&quot;your_password&quot;)<\/p>\n<p>    driver.find_element_by_name(&quot;submit&quot;).click()<\/p>\n<p>    # \u4fdd\u5b58 cookies \u5230\u6587\u4ef6<\/p>\n<p>    with open(&quot;cookies.pkl&quot;, &quot;wb&quot;) as f:<\/p>\n<p>        pickle.dump(driver.get_cookies(), f)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u5df2\u7ecf\u767b\u5f55&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u540c\u4e00\u4e2a\u6d4f\u89c8\u5668\u5b9e\u4f8b\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c<\/strong><\/h2>\n<p>driver.get(&quot;https:\/\/example.com\/profile&quot;)<\/p>\n<p>print(driver.page_source)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>Requests-HTML<\/h3>\n<\/p>\n<p><p><code>requests-html<\/code> \u662f\u4e00\u4e2a\u96c6\u6210\u4e86 <code>requests<\/code> \u548c <code>pyquery<\/code> \u7684\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c Web \u6293\u53d6\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u3002\u5b83\u4e5f\u63d0\u4f9b\u4e86\u4f1a\u8bdd\u7ba1\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u4fdd\u6301\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from requests_html import HTMLSession<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a HTMLSession \u5bf9\u8c61<\/strong><\/h2>\n<p>session = HTMLSession()<\/p>\n<h2><strong>\u4f7f\u7528 session \u5bf9\u8c61\u8fdb\u884c\u767b\u5f55<\/strong><\/h2>\n<p>login_url = &quot;https:\/\/example.com\/login&quot;<\/p>\n<p>login_data = {<\/p>\n<p>    &quot;username&quot;: &quot;your_username&quot;,<\/p>\n<p>    &quot;password&quot;: &quot;your_password&quot;<\/p>\n<p>}<\/p>\n<p>response = session.post(login_url, data=login_data)<\/p>\n<h2><strong>\u68c0\u67e5\u767b\u5f55\u662f\u5426\u6210\u529f<\/strong><\/h2>\n<p>if response.ok:<\/p>\n<p>    print(&quot;\u767b\u5f55\u6210\u529f&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u767b\u5f55\u5931\u8d25&quot;)<\/p>\n<h2><strong>\u4f7f\u7528\u540c\u4e00\u4e2a session \u5bf9\u8c61\u8fdb\u884c\u5176\u4ed6\u8bf7\u6c42<\/strong><\/h2>\n<p>profile_url = &quot;https:\/\/example.com\/profile&quot;<\/p>\n<p>profile_response = session.get(profile_url)<\/p>\n<p>print(profile_response.html.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6574\u4e2a\u4f1a\u8bdd\u671f\u95f4\u4fdd\u6301\u767b\u5f55\u72b6\u6001\uff0c\u907f\u514d\u91cd\u590d\u767b\u5f55\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728 Python \u81ea\u52a8\u5316\u4efb\u52a1\u4e2d\uff0c\u53ea\u767b\u5f55\u4e00\u6b21\u662f\u63d0\u9ad8\u6548\u7387\u548c\u51cf\u5c11\u91cd\u590d\u64cd\u4f5c\u7684\u91cd\u8981\u7b56\u7565\u3002<strong>\u6301\u4e45\u5316\u4f1a\u8bdd\u3001\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong> \u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u4e09\u79cd\u4e3b\u8981\u65b9\u6cd5\u3002\u901a\u8fc7\u4f7f\u7528 <code>requests<\/code> \u5e93\u7684 <code>Session<\/code> \u5bf9\u8c61\u3001\u4fdd\u5b58\u548c\u52a0\u8f7d cookies\u3001\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u4ee5\u53ca\u4f7f\u7528 Selenium \u548c <code>requests-html<\/code> \u7b49\u7b2c\u4e09\u65b9\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6574\u4e2a\u81ea\u52a8\u5316\u4efb\u52a1\u671f\u95f4\u4fdd\u6301\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\uff0c\u907f\u514d\u91cd\u590d\u767b\u5f55\uff0c\u4ece\u800c\u63d0\u9ad8\u4efb\u52a1\u7684\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u81ea\u52a8\u5316\u5b9e\u73b0\u53ea\u767b\u5f55\u4e00\u6b21\u7684\u529f\u80fd\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u81ea\u52a8\u5316\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u5229\u7528Python\u7684\u5e93\uff0c\u6bd4\u5982<code>requests<\/code>\u548c<code>selenium<\/code>\uff0c\u6765\u5b9e\u73b0\u53ea\u767b\u5f55\u4e00\u6b21\u7684\u529f\u80fd\u3002\u901a\u8fc7\u4fdd\u5b58\u767b\u5f55\u72b6\u6001\u7684cookie\uff0c\u540e\u7eed\u7684\u8bf7\u6c42\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5df2\u767b\u5f55\u7684\u72b6\u6001\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u590d\u767b\u5f55\u3002<\/p>\n<p><strong>\u5728Python\u81ea\u52a8\u5316\u4e2d\uff0c\u5982\u4f55\u7ba1\u7406\u548c\u4fdd\u5b58\u767b\u5f55\u72b6\u6001\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u4e2d\u7684session\u5bf9\u8c61\uff0c\u5b83\u4f1a\u81ea\u52a8\u5904\u7406cookie\u7684\u5b58\u50a8\u548c\u7ba1\u7406\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2asession\uff0c\u60a8\u53ef\u4ee5\u5728\u591a\u4e2a\u8bf7\u6c42\u4e2d\u4fdd\u6301\u767b\u5f55\u72b6\u6001\uff0c\u4ece\u800c\u907f\u514d\u6bcf\u6b21\u90fd\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<p><strong>\u5982\u679c\u767b\u5f55\u540e\u9700\u8981\u6267\u884c\u591a\u4e2a\u64cd\u4f5c\uff0c\u5982\u4f55\u786e\u4fdd\u6bcf\u4e2a\u64cd\u4f5c\u90fd\u80fd\u6b63\u5e38\u6267\u884c\uff1f<\/strong><br \/>\u5728\u767b\u5f55\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u8fd4\u56de\u7684\u54cd\u5e94\u72b6\u6001\u7801\u6216\u7279\u5b9a\u5143\u7d20\u6765\u786e\u8ba4\u7528\u6237\u662f\u5426\u4ecd\u7136\u5904\u4e8e\u767b\u5f55\u72b6\u6001\u3002\u8fd9\u6837\uff0c\u5982\u679c\u72b6\u6001\u53d1\u751f\u53d8\u5316\uff0c\u53ef\u4ee5\u53ca\u65f6\u91cd\u65b0\u767b\u5f55\u4ee5\u4fdd\u6301\u64cd\u4f5c\u7684\u8fde\u7eed\u6027\u3002\u4f7f\u7528<code>selenium<\/code>\u65f6\uff0c\u53ef\u4ee5\u5b9a\u671f\u68c0\u67e5\u9875\u9762\u4e0a\u7684\u767b\u5f55\u6807\u8bc6\uff0c\u4ee5\u786e\u8ba4\u662f\u5426\u9700\u8981\u91cd\u65b0\u8ba4\u8bc1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python \u81ea\u52a8\u5316\u5982\u4f55\u53ea\u767b\u5f55\u4e00\u6b21\uff1a \u5728\u8fdb\u884c Python \u81ea\u52a8\u5316\u4efb\u52a1\u65f6\uff0c\u4f7f\u7528\u6301\u4e45\u5316\u4f1a\u8bdd\u3001\u4f7f\u7528\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1130996,"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\/1130989"}],"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=1130989"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1130989\/revisions"}],"predecessor-version":[{"id":1131002,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1130989\/revisions\/1131002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1130996"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1130989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1130989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1130989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}