{"id":1035148,"date":"2024-12-31T11:56:23","date_gmt":"2024-12-31T03:56:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1035148.html"},"modified":"2024-12-31T11:56:25","modified_gmt":"2024-12-31T03:56:25","slug":"python%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e7%94%b5%e5%bd%b1%e7%a5%a8%e6%88%bf","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1035148.html","title":{"rendered":"python\u5982\u4f55\u83b7\u53d6\u7535\u5f71\u7968\u623f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/b8a8dd1c-a8f5-4176-ba0b-23df784e658f.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u83b7\u53d6\u7535\u5f71\u7968\u623f\" \/><\/p>\n<p><p> \u4e00\u3001Python\u83b7\u53d6\u7535\u5f71\u7968\u623f\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u3001\u8c03\u7528\u7b2c\u4e09\u65b9API\u3001\u4f7f\u7528\u6570\u636e\u5206\u6790\u5e93\u3001\u901a\u8fc7\u7f51\u9875\u89e3\u6790\u5de5\u5177\u3002<strong>\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f<\/strong>\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u83b7\u53d6\u5230\u8bb8\u591a\u516c\u5f00\u7684\u7535\u5f71\u7968\u623f\u6570\u636e\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u662f\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u6709\u6548\u65b9\u6cd5\u4e4b\u4e00\u3002\u901a\u8fc7\u7f16\u5199\u722c\u866b\u7a0b\u5e8f\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u4e00\u4e9b\u63d0\u4f9b\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u7f51\u7ad9\uff0c\u89e3\u6790\u7f51\u9875\u4e2d\u7684\u4fe1\u606f\u5e76\u5c06\u6570\u636e\u63d0\u53d6\u51fa\u6765\u3002Python\u4e2d\u6709\u591a\u4e2a\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>requests<\/code>\u548c<code>BeautifulSoup<\/code>\u3002\u901a\u8fc7<code>requests<\/code>\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u83b7\u53d6\u7f51\u9875\u7684HTML\u5185\u5bb9\uff0c\u518d\u4f7f\u7528<code>BeautifulSoup<\/code>\u5e93\u89e3\u6790HTML\u5e76\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u83b7\u53d6\u7535\u5f71\u7968\u623f<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u6240\u9700\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u722c\u866b\u7a0b\u5e8f\u4e4b\u524d\uff0c\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5<code>requests<\/code>\u548c<code>BeautifulSoup<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p>pip install beautifulsoup4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u53d1\u9001HTTP\u8bf7\u6c42<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528<code>requests<\/code>\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u4ee5\u83b7\u53d6\u7f51\u9875\u7684HTML\u5185\u5bb9\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u7528\u4e8e\u8bf7\u6c42\u4e00\u4e2a\u5305\u542b\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u7f51\u9875\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>url = &quot;https:\/\/example.com\/movies&quot;<\/p>\n<p>response = requests.get(url)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    html_content = response.content<\/p>\n<p>else:<\/p>\n<p>    print(&quot;F<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led to retrieve the webpage.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>requests.get<\/code>\u65b9\u6cd5\u53d1\u9001GET\u8bf7\u6c42\uff0c\u5e76\u68c0\u67e5\u54cd\u5e94\u7684\u72b6\u6001\u7801\u662f\u5426\u4e3a200\uff08\u8868\u793a\u8bf7\u6c42\u6210\u529f\uff09\u3002\u5982\u679c\u8bf7\u6c42\u6210\u529f\uff0c\u5219\u5c06\u7f51\u9875\u5185\u5bb9\u5b58\u50a8\u5728<code>html_content<\/code>\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u89e3\u6790HTML\u5185\u5bb9<\/li>\n<\/ol>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528<code>BeautifulSoup<\/code>\u5e93\u89e3\u6790HTML\u5185\u5bb9\uff0c\u5e76\u63d0\u53d6\u6240\u9700\u7684\u7535\u5f71\u7968\u623f\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u89e3\u6790HTML\u5e76\u63d0\u53d6\u7535\u5f71\u540d\u79f0\u548c\u7968\u623f\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<p>soup = BeautifulSoup(html_content, &quot;html.parser&quot;)<\/p>\n<p>movies = []<\/p>\n<p>for movie in soup.find_all(&quot;div&quot;, class_=&quot;movie&quot;):<\/p>\n<p>    title = movie.find(&quot;h2&quot;, class_=&quot;title&quot;).text<\/p>\n<p>    box_office = movie.find(&quot;span&quot;, class_=&quot;box_office&quot;).text<\/p>\n<p>    movies.append({&quot;title&quot;: title, &quot;box_office&quot;: box_office})<\/p>\n<p>for movie in movies:<\/p>\n<p>    print(f&quot;Title: {movie[&#39;title&#39;]}, Box Office: {movie[&#39;box_office&#39;]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>BeautifulSoup<\/code>\u89e3\u6790HTML\u5185\u5bb9\uff0c\u5e76\u4f7f\u7528<code>find_all<\/code>\u65b9\u6cd5\u67e5\u627e\u6240\u6709\u5305\u542b\u7535\u5f71\u6570\u636e\u7684<code>div<\/code>\u5143\u7d20\u3002\u7136\u540e\uff0c\u6211\u4eec\u63d0\u53d6\u6bcf\u90e8\u7535\u5f71\u7684\u6807\u9898\u548c\u7968\u623f\u6570\u636e\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u8c03\u7528\u7b2c\u4e09\u65b9API\u83b7\u53d6\u7535\u5f71\u7968\u623f<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u5916\uff0c\u8c03\u7528\u7b2c\u4e09\u65b9API\u4e5f\u662f\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u6709\u6548\u65b9\u6cd5\u3002\u8bb8\u591a\u7f51\u7ad9\u548c\u670d\u52a1\u63d0\u4f9b\u7535\u5f71\u7968\u623f\u6570\u636e\u7684API\u63a5\u53e3\uff0c\u4f8b\u5982OMDb API\u3001The Movie Database (TMDb) API\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528TMDb API\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u6240\u9700\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u5b89\u88c5<code>requests<\/code>\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u83b7\u53d6API\u5bc6\u94a5<\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528TMDb API\u4e4b\u524d\uff0c\u9700\u8981\u6ce8\u518c\u4e00\u4e2a\u8d26\u6237\u5e76\u83b7\u53d6API\u5bc6\u94a5\u3002\u53ef\u4ee5\u5728TMDb\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0a\u5b8c\u6210\u6ce8\u518c\u5e76\u751f\u6210API\u5bc6\u94a5\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u53d1\u9001API\u8bf7\u6c42<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528TMDb API\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>api_key = &quot;YOUR_API_KEY&quot;<\/p>\n<p>movie_id = 550  # \u7535\u5f71\u7684TMDb ID<\/p>\n<p>url = f&quot;https:\/\/api.themoviedb.org\/3\/movie\/{movie_id}\/box_office?api_key={api_key}&quot;<\/p>\n<p>response = requests.get(url)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    data = response.json()<\/p>\n<p>    title = data[&quot;title&quot;]<\/p>\n<p>    box_office = data[&quot;revenue&quot;]<\/p>\n<p>    print(f&quot;Title: {title}, Box Office: {box_office}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Failed to retrieve the movie data.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>requests.get<\/code>\u65b9\u6cd5\u53d1\u9001GET\u8bf7\u6c42\uff0c\u5e76\u68c0\u67e5\u54cd\u5e94\u7684\u72b6\u6001\u7801\u662f\u5426\u4e3a200\uff08\u8868\u793a\u8bf7\u6c42\u6210\u529f\uff09\u3002\u5982\u679c\u8bf7\u6c42\u6210\u529f\uff0c\u5219\u5c06\u54cd\u5e94\u6570\u636e\u89e3\u6790\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u63d0\u53d6\u7535\u5f71\u7684\u6807\u9898\u548c\u7968\u623f\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u6570\u636e\u5206\u6790\u5e93\u83b7\u53d6\u7535\u5f71\u7968\u623f<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u6570\u636e\u5206\u6790\u5e93\u4e5f\u662f\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u6709\u6548\u65b9\u6cd5\u4e4b\u4e00\u3002Python\u4e2d\u6709\u591a\u4e2a\u6570\u636e\u5206\u6790\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>pandas<\/code>\u3002\u901a\u8fc7<code>pandas<\/code>\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u8bfb\u53d6\u548c\u5206\u6790\u5305\u542b\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u6587\u4ef6\uff0c\u4f8b\u5982CSV\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u6240\u9700\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u5b89\u88c5<code>pandas<\/code>\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u8bfb\u53d6CSV\u6587\u4ef6<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528<code>pandas<\/code>\u5e93\u8bfb\u53d6\u5305\u542b\u7535\u5f71\u7968\u623f\u6570\u636e\u7684CSV\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>file_path = &quot;movies.csv&quot;<\/p>\n<p>df = pd.read_csv(file_path)<\/p>\n<p>print(df.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pandas.read_csv<\/code>\u65b9\u6cd5\u8bfb\u53d6CSV\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a<code>DataFrame<\/code>\u5bf9\u8c61\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>head<\/code>\u65b9\u6cd5\u663e\u793a\u524d\u4e94\u884c\u6570\u636e\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u5206\u6790\u6570\u636e<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7<code>pandas<\/code>\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5bf9\u7535\u5f71\u7968\u623f\u6570\u636e\u8fdb\u884c\u5206\u6790\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u8ba1\u7b97\u6bcf\u90e8\u7535\u5f71\u7684\u603b\u7968\u623f\u6536\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">total_box_office = df[&quot;box_office&quot;].sum()<\/p>\n<p>print(f&quot;Total Box Office: {total_box_office}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>sum<\/code>\u65b9\u6cd5\u8ba1\u7b97<code>box_office<\/code>\u5217\u7684\u603b\u548c\uff0c\u5e76\u6253\u5370\u603b\u7968\u623f\u6536\u5165\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u901a\u8fc7\u7f51\u9875\u89e3\u6790\u5de5\u5177\u83b7\u53d6\u7535\u5f71\u7968\u623f<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u5916\uff0c\u4f7f\u7528\u7f51\u9875\u89e3\u6790\u5de5\u5177\u4e5f\u662f\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u6709\u6548\u65b9\u6cd5\u3002Python\u4e2d\u6709\u591a\u4e2a\u7f51\u9875\u89e3\u6790\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>lxml<\/code>\u3002\u901a\u8fc7<code>lxml<\/code>\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u89e3\u6790HTML\u548cXML\u6587\u6863\uff0c\u5e76\u63d0\u53d6\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u6240\u9700\u5e93<\/li>\n<\/ol>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u5b89\u88c5<code>lxml<\/code>\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install lxml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u89e3\u6790HTML\u5185\u5bb9<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528<code>lxml<\/code>\u5e93\u89e3\u6790HTML\u5185\u5bb9\uff0c\u5e76\u63d0\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from lxml import etree<\/p>\n<p>html_content = &quot;&quot;&quot;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>  &lt;body&gt;<\/p>\n<p>    &lt;div class=&quot;movie&quot;&gt;<\/p>\n<p>      &lt;h2 class=&quot;title&quot;&gt;Movie 1&lt;\/h2&gt;<\/p>\n<p>      &lt;span class=&quot;box_office&quot;&gt;1000000&lt;\/span&gt;<\/p>\n<p>    &lt;\/div&gt;<\/p>\n<p>    &lt;div class=&quot;movie&quot;&gt;<\/p>\n<p>      &lt;h2 class=&quot;title&quot;&gt;Movie 2&lt;\/h2&gt;<\/p>\n<p>      &lt;span class=&quot;box_office&quot;&gt;2000000&lt;\/span&gt;<\/p>\n<p>    &lt;\/div&gt;<\/p>\n<p>  &lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<p>tree = etree.HTML(html_content)<\/p>\n<p>movies = []<\/p>\n<p>for movie in tree.xpath(&quot;\/\/div[@class=&#39;movie&#39;]&quot;):<\/p>\n<p>    title = movie.xpath(&quot;.\/\/h2[@class=&#39;title&#39;]\/text()&quot;)[0]<\/p>\n<p>    box_office = movie.xpath(&quot;.\/\/span[@class=&#39;box_office&#39;]\/text()&quot;)[0]<\/p>\n<p>    movies.append({&quot;title&quot;: title, &quot;box_office&quot;: box_office})<\/p>\n<p>for movie in movies:<\/p>\n<p>    print(f&quot;Title: {movie[&#39;title&#39;]}, Box Office: {movie[&#39;box_office&#39;]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>etree.HTML<\/code>\u65b9\u6cd5\u89e3\u6790HTML\u5185\u5bb9\uff0c\u5e76\u4f7f\u7528<code>xpath<\/code>\u65b9\u6cd5\u67e5\u627e\u6240\u6709\u5305\u542b\u7535\u5f71\u6570\u636e\u7684<code>div<\/code>\u5143\u7d20\u3002\u7136\u540e\uff0c\u6211\u4eec\u63d0\u53d6\u6bcf\u90e8\u7535\u5f71\u7684\u6807\u9898\u548c\u7968\u623f\u6570\u636e\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u3001\u8c03\u7528\u7b2c\u4e09\u65b9API\u3001\u4f7f\u7528\u6570\u636e\u5206\u6790\u5e93\u3001\u901a\u8fc7\u7f51\u9875\u89e3\u6790\u5de5\u5177\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u548c\u5206\u6790\u7535\u5f71\u7968\u623f\u6570\u636e\uff0c\u4e3a\u7535\u5f71\u5e02\u573a\u5206\u6790\u548c\u51b3\u7b56\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u83b7\u53d6\u5b9e\u65f6\u7535\u5f71\u7968\u623f\u6570\u636e\uff1f<\/strong><br \/>\u8981\u83b7\u53d6\u5b9e\u65f6\u7535\u5f71\u7968\u623f\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u7684\u7f51\u7edc\u722c\u866b\u6280\u672f\u3002\u901a\u8fc7requests\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\u5230\u76f8\u5173\u7535\u5f71\u7f51\u7ad9\uff08\u5982Box Office Mojo\u6216IMDb\uff09\uff0c\u7136\u540e\u5229\u7528BeautifulSoup\u5e93\u89e3\u6790HTML\u5185\u5bb9\u63d0\u53d6\u7968\u623f\u4fe1\u606f\u3002\u786e\u4fdd\u9075\u5faa\u7f51\u7ad9\u7684\u4f7f\u7528\u6761\u6b3e\uff0c\u5e76\u8003\u8651\u4f7f\u7528API\u63a5\u53e3\uff08\u5982\u679c\u53ef\u7528\uff09\u4ee5\u66f4\u7a33\u5b9a\u5730\u83b7\u53d6\u6570\u636e\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9bPython\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u83b7\u53d6\u7535\u5f71\u7968\u623f\u4fe1\u606f\uff1f<\/strong><br \/>\u5728\u83b7\u53d6\u7535\u5f71\u7968\u623f\u4fe1\u606f\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2aPython\u5e93\u3002requests\u5e93\u7528\u4e8e\u53d1\u9001\u7f51\u7edc\u8bf7\u6c42\uff0cBeautifulSoup\u7528\u4e8e\u89e3\u6790HTML\u6587\u6863\uff0cScrapy\u5219\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7f51\u7edc\u722c\u866b\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u9ad8\u6548\u5730\u6293\u53d6\u6570\u636e\u3002\u6b64\u5916\uff0c\u4e00\u4e9b\u7b2c\u4e09\u65b9API\uff08\u5982OMDb API\uff09\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u7535\u5f71\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u7968\u623f\u6570\u636e\u3002<\/p>\n<p><strong>\u83b7\u53d6\u7535\u5f71\u7968\u623f\u6570\u636e\u540e\uff0c\u5982\u4f55\u8fdb\u884c\u6570\u636e\u5206\u6790\uff1f<\/strong><br \/>\u4e00\u65e6\u83b7\u5f97\u7535\u5f71\u7968\u623f\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u901a\u8fc7\u6570\u636e\u6e05\u6d17\uff0c\u60a8\u53ef\u4ee5\u6574\u7406\u7968\u623f\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528Matplotlib\u6216Seaborn\u53ef\u89c6\u5316\u5e93\u751f\u6210\u5404\u79cd\u56fe\u8868\uff0c\u5e2e\u52a9\u60a8\u76f4\u89c2\u7406\u89e3\u7968\u623f\u8d8b\u52bf\u3002\u540c\u65f6\uff0c\u60a8\u4e5f\u53ef\u4ee5\u5229\u7528\u7edf\u8ba1\u5206\u6790\u65b9\u6cd5\u5bf9\u7968\u623f\u6570\u636e\u8fdb\u884c\u6df1\u5165\u5206\u6790\uff0c\u6316\u6398\u6f5c\u5728\u7684\u5e02\u573a\u89c4\u5f8b\u548c\u5f71\u7247\u8868\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001Python\u83b7\u53d6\u7535\u5f71\u7968\u623f\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u7f51\u7edc\u722c\u866b\u6280\u672f\u3001\u8c03\u7528\u7b2c\u4e09\u65b9API\u3001\u4f7f\u7528\u6570\u636e\u5206\u6790\u5e93\u3001\u901a\u8fc7\u7f51\u9875\u89e3\u6790\u5de5\u5177\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1035155,"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\/1035148"}],"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=1035148"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1035148\/revisions"}],"predecessor-version":[{"id":1035158,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1035148\/revisions\/1035158"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1035155"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1035148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1035148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1035148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}