{"id":111867,"date":"2026-10-02T01:16:54","date_gmt":"2026-10-01T17:16:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/111867.html"},"modified":"2026-10-02T01:16:54","modified_gmt":"2026-10-01T17:16:54","slug":"%e7%88%ac%e8%99%ab%e9%a1%b9%e7%9b%ae-%e8%8e%b7%e5%8f%96%e9%ab%98%e5%88%86%e7%94%b5%e5%bd%b1%e7%9a%84%e6%95%b0%e6%8d%ae%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/111867.html","title":{"rendered":"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3"},"content":{"rendered":"<p>  \u4e2a\u4eba\u4e3b\u9875&#xff1a;<br \/>\n &gt; for_ever_love__ &lt; &#xff08;\u6b22\u8fce\u5404\u4f4d\u5927\u4f6c\u8385\u4e34&#x1f60a;&#xff09;<br \/>\n \u5176\u4ed6\u680f\u76ee:<br \/>\n&gt; \u6211\u60f3\u5b66python\u4e86 &lt; <\/p>\n<p>\u5176\u4ed6\u680f\u76ee: &gt; iOS\u9879\u76ee\u603b\u7ed3\u5927\u5168 &lt;<\/p>\n<p>\u5176\u4ed6\u680f\u76ee: &gt; iOS UI &lt;<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3<\/li>\n<li>\n<ul>\n<li>\u4e00\u3001\u9879\u76ee\u6982\u8ff0<\/li>\n<li>\u4e8c\u3001\u6838\u5fc3\u6a21\u5757\u62c6\u89e3<\/li>\n<li>\n<ul>\n<li>1. \u8bf7\u6c42\u5934\u6784\u9020(\u53cd\u722c\u57fa\u7840)<\/li>\n<li>2. \u699c\u5355\u6570\u636e\u83b7\u53d6(\u5206\u9875\u5904\u7406)<\/li>\n<li>3. \u8be6\u60c5\u9875\u89e3\u6790(XPath)<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u95ee\u9898\u53d1\u73b0\u4e0e\u6539\u8fdb:\u4ece\u4f4d\u7f6e\u7d22\u5f15\u5230 class \u8bed\u4e49\u5b9a\u4f4d<\/li>\n<li>\n<ul>\n<li>3.1 \u521d\u59cb\u7248\u672c\u7684\u5199\u6cd5<\/li>\n<li>3.2 \u8fd0\u884c\u540e\u53d1\u73b0\u7684\u95ee\u9898<\/li>\n<li>3.3 \u539f\u56e0\u5206\u6790<\/li>\n<li>3.4 \u6539\u8fdb\u65b9\u6848:\u7528 &#096;&#064;class&#096; \u8bed\u4e49\u5b9a\u4f4d<\/li>\n<li>3.5 \u5f15\u7533:XPath \u5b9a\u4f4d\u65b9\u5f0f\u7684\u7a33\u5b9a\u6027\u4f18\u5148\u7ea7<\/li>\n<li>3.6 \u76f8\u540c\u601d\u8def\u53ef\u4ee5\u7ee7\u7eed\u4f18\u5316\u7684\u5730\u65b9<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001\u6570\u636e\u4fdd\u5b58(CSV)<\/li>\n<li>\u4e94\u3001\u53ef\u7ee7\u7eed\u4f18\u5316\u70b9<\/li>\n<li>\n<ul>\n<li>1. \u5b57\u7b26\u4e32\u62fc\u63a5\u8868\u5355\u53c2\u6570\u4e0d\u4f18\u96c5<\/li>\n<li>2. \u6ca1\u6709\u5f02\u5e38\u5904\u7406<\/li>\n<li>3. \u7f3a\u5c11\u8bf7\u6c42\u95f4\u9694,\u5bb9\u6613\u88ab\u5c01<\/li>\n<li>4. \u5b57\u6bb5\u62bd\u53d6\u8fc7\u6563,\u53ef\u4ee5\u62bd\u6210\u914d\u7f6e<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001\u672c\u9879\u76ee\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e32\u8054<\/li>\n<li>\u4e03\u3001\u603b\u7ed3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3<\/h2>\n<h3>\u4e00\u3001\u9879\u76ee\u6982\u8ff0<\/h3>\n<p>\u672c\u9879\u76ee\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7535\u5f71\u6570\u636e\u722c\u866b,\u4ece TMDB(The Movie Database)\u7f51\u7ad9\u6293\u53d6\u9ad8\u5206\u7535\u5f71\u699c\u5355\u6570\u636e,\u89e3\u6790\u7535\u5f71\u8be6\u60c5\u9875,\u6700\u7ec8\u5c06\u6570\u636e\u4fdd\u5b58\u4e3a CSV \u6587\u4ef6\u3002<\/p>\n<p>\u6574\u4f53\u6d41\u7a0b:<\/p>\n<p>\u83b7\u53d6\u699c\u5355\u9875 \u2192 \u89e3\u6790\u7535\u5f71\u8be6\u60c5\u9875 URL \u2192 \u8bf7\u6c42\u8be6\u60c5\u9875 \u2192 XPath \u89e3\u6790\u5b57\u6bb5 \u2192 \u6c47\u603b\u5199\u5165 CSV<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u6838\u5fc3\u6a21\u5757\u62c6\u89e3<\/h3>\n<h4>1. \u8bf7\u6c42\u5934\u6784\u9020(\u53cd\u722c\u57fa\u7840)<\/h4>\n<p>headers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;Connection&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;close&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;User-Agent&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Mozilla\/5.0 &#8230; Chrome\/152.0.0.0 Safari\/537.36&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;Accept-Language&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;zh-CN, zh; q &#061; 0.9&#034;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u51e0\u4e2a\u8981\u70b9:<\/p>\n<ul>\n<li>User-Agent:\u4f2a\u88c5\u6210\u771f\u5b9e\u6d4f\u89c8\u5668,\u907f\u514d\u88ab\u670d\u52a1\u5668\u8bc6\u522b\u4e3a\u722c\u866b\u76f4\u63a5\u62d2\u7edd<\/li>\n<li>Accept-Language:\u544a\u8bc9\u670d\u52a1\u5668\u8fd4\u56de\u4e2d\u6587\u5185\u5bb9(\u5f71\u54cd TMDB \u9875\u9762\u6587\u6848)<\/li>\n<li>Connection: close:\u6bcf\u6b21\u8bf7\u6c42\u5b8c\u5173\u95ed\u8fde\u63a5,\u907f\u514d\u8fde\u63a5\u6c60\u88ab\u5360\u7528\u8fc7\u4e45<\/li>\n<\/ul>\n<p>\u5728\u8be6\u60c5\u9875\u8bf7\u6c42\u91cc\u8fd8\u989d\u5916\u52a0\u4e86 Referer,\u6a21\u62df&#034;\u4ece\u699c\u5355\u9875\u70b9\u8fdb\u8be6\u60c5\u9875&#034;\u7684\u771f\u5b9e\u8df3\u8f6c\u6765\u6e90\u3002<\/p>\n<p>\u53cd\u722c\u7684\u7b2c\u4e00\u5c42,\u5c31\u662f\u8ba9\u8bf7\u6c42&#034;\u770b\u8d77\u6765\u50cf\u6b63\u5e38\u7528\u6237\u53d1\u51fa\u7684&#034;\u3002<\/p>\n<hr \/>\n<h4>2. \u699c\u5355\u6570\u636e\u83b7\u53d6(\u5206\u9875\u5904\u7406)<\/h4>\n<p>TMDB \u7684\u9ad8\u5206\u699c\u6709\u4e24\u4e2a\u5165\u53e3:<\/p>\n<table>\n<tr>\u9875\u7801URL\u8bf7\u6c42\u65b9\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>\u7b2c 1 \u9875<\/td>\n<td>\/movie\/top-rated<\/td>\n<td>GET<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c 2~5 \u9875<\/td>\n<td>\/discover\/movie\/items<\/td>\n<td>POST(\u5e26\u8868\u5355\u53c2\u6570)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"token keyword\">for<\/span> page_num <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">6<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> page_num <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        response <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>TMDB_TOP_URL_1<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        response <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>TMDB_TOP_URL_2<span class=\"token punctuation\">,<\/span> data<span class=\"token operator\">&#061;<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;&#8230;&amp;page&#061;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>page_num<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&amp;&#8230;&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u7b2c 2 \u9875\u5f00\u59cb\u8981\u7528 POST?<\/p>\n<p>TMDB \u7684 discover \u63a5\u53e3\u7b5b\u9009\u6761\u4ef6\u975e\u5e38\u591a(\u65e5\u671f\u3001\u8bed\u8a00\u3001\u8bc4\u5206\u533a\u95f4\u3001\u65f6\u957f\u8303\u56f4\u2026\u2026),\u7528 POST \u8868\u5355\u63d0\u4ea4\u66f4\u5408\u9002,URL \u4e5f\u66f4\u5e72\u51c0\u3002\u53c2\u6570\u91cc\u7684\u5173\u952e\u9879:<\/p>\n<ul>\n<li>sort_by&#061;vote_average.desc:\u6309\u5e73\u5747\u5206\u964d\u5e8f<\/li>\n<li>vote_count.gte&#061;300:\u8fc7\u6ee4\u6389\u8bc4\u5206\u4eba\u6570\u592a\u5c11\u7684\u7535\u5f71(\u9632\u6b62&#034;1 \u4eba\u6253 10 \u5206&#034;\u767b\u9876)<\/li>\n<li>with_runtime.gte\/lte:\u65f6\u957f\u8303\u56f4<\/li>\n<\/ul>\n<p>\u5206\u9875\u722c\u53d6\u7684\u6838\u5fc3\u662f\u89c2\u5bdf\u8bf7\u6c42\u89c4\u5f8b,\u627e\u5230\u7ffb\u9875\u65f6\u552f\u4e00\u53d8\u5316\u7684\u53c2\u6570(\u8fd9\u91cc\u662f page)\u3002<\/p>\n<hr \/>\n<h4>3. \u8be6\u60c5\u9875\u89e3\u6790(XPath)<\/h4>\n<p>movie_doc <span class=\"token operator\">&#061;<\/span> html<span class=\"token punctuation\">.<\/span>fromstring<span class=\"token punctuation\">(<\/span>movie_response<span class=\"token punctuation\">.<\/span>text<span class=\"token punctuation\">)<\/span><\/p>\n<p>movie_name <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/h2\/a\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nmovie_years <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/&#8230;\/h2\/span\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><\/p>\n<p>\u5173\u952e\u70b9:<\/p>\n<ul>\n<li>html.fromstring():\u628a HTML \u5b57\u7b26\u4e32\u8f6c\u6210\u7ed3\u6784\u5316\u6587\u6863\u5bf9\u8c61,\u4e4b\u540e\u53ef\u4ee5\u7528 XPath \u67e5\u8be2<\/li>\n<li>xpath() \u8fd4\u56de\u7684\u662f\u5217\u8868,\u5373\u4f7f\u53ea\u6709\u4e00\u4e2a\u7ed3\u679c\u4e5f\u662f [xxx]<\/li>\n<li>\u53d6\u503c\u65f6\u7edf\u4e00\u505a\u7a7a\u5217\u8868\u515c\u5e95:<\/li>\n<\/ul>\n<p><span class=\"token string\">&#039;\u7535\u5f71\u540d&#039;<\/span><span class=\"token punctuation\">:<\/span> movie_name<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>movie_name<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token string\">&#034;&#034;<\/span><\/p>\n<p>XPath \u5b9a\u4f4d\u4e00\u5b9a\u8981\u5148\u5728\u6d4f\u89c8\u5668 F12 \u91cc\u9a8c\u8bc1,\u76f4\u63a5\u6284\u8def\u5f84\u5f88\u5bb9\u6613\u56e0\u4e3a\u9875\u9762\u52a8\u6001\u6e32\u67d3\u800c\u843d\u7a7a\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u95ee\u9898\u53d1\u73b0\u4e0e\u6539\u8fdb:\u4ece\u4f4d\u7f6e\u7d22\u5f15\u5230 class \u8bed\u4e49\u5b9a\u4f4d<\/h3>\n<h4>3.1 \u521d\u59cb\u7248\u672c\u7684\u5199\u6cd5<\/h4>\n<p>\u8be6\u60c5\u9875\u5934\u90e8\u7ed3\u6784\u91cc,\u4e0a\u6620\u65e5\u671f\u3001\u6807\u7b7e\u3001\u65f6\u957f\u8fd9\u4e09\u4e2a\u5b57\u6bb5,\u6700\u521d\u662f\u7528\u7eaf\u4f4d\u7f6e\u7d22\u5f15\u5b9a\u4f4d\u7684:<\/p>\n<p><span class=\"token comment\"># \u4e0a\u6620\u65e5\u671f<\/span><br \/>\nmovie_data <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[2]\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6807\u7b7e<\/span><br \/>\nmovie_tags <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[3]\/a\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u65f6\u957f<\/span><br \/>\nmovie_cost_times <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[4]\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5f53\u65f6\u6293\u53d6\u7b2c\u4e00\u9875\u51e0\u90e8\u7535\u5f71\u65f6\u770b\u8d77\u6765\u662f\u6b63\u5e38\u7684,\u56e0\u4e3a\u8fd9\u51e0\u90e8\u7535\u5f71\u7684\u8be6\u60c5\u9875\u7ed3\u6784\u4e00\u81f4,span[2] \/ span[3] \/ span[4] \u6070\u597d\u4e00\u4e00\u5bf9\u5e94\u4e0a\u6620\u65e5\u671f\u3001\u6807\u7b7e\u548c\u65f6\u957f\u3002<\/p>\n<h4>3.2 \u8fd0\u884c\u540e\u53d1\u73b0\u7684\u95ee\u9898<\/h4>\n<p>\u722c\u5b8c 5 \u9875\u3001\u4e0a\u767e\u90e8\u7535\u5f71\u4e4b\u540e,\u68c0\u67e5 CSV \u7ed3\u679c\u53d1\u73b0:<\/p>\n<ul>\n<li>\u90e8\u5206\u7535\u5f71\u7684\u4e0a\u6620\u65e5\u671f\u662f\u7a7a\u767d<\/li>\n<li>\u90e8\u5206\u7535\u5f71\u7684\u6807\u7b7e\u5217\u5185\u5bb9\u9519\u4f4d,\u6216\u8005\u5e72\u8106\u4e3a\u7a7a<\/li>\n<li>\u90e8\u5206\u7535\u5f71\u7684\u65f6\u957f\u662f\u7a7a\u767d<\/li>\n<\/ul>\n<p>\u4f46\u540c\u4e00\u90e8\u7535\u5f71\u7684\u7535\u5f71\u540d\u548c\u5e74\u4efd\u90fd\u662f\u6b63\u5e38\u7684\u3002<\/p>\n<h4>3.3 \u539f\u56e0\u5206\u6790<\/h4>\n<p>\u56de\u5230 TMDB \u8be6\u60c5\u9875\u7684\u7ed3\u6784\u4e0a\u627e\u539f\u56e0\u3002\u5934\u90e8\u90a3\u4e00\u884c div \u91cc,span \u7684\u987a\u5e8f\u5e76\u4e0d\u662f\u56fa\u5b9a\u6b7b\u7684,\u5b83\u5927\u81f4\u6309\u8fd9\u6837\u7684\u987a\u5e8f\u6392\u5e03:<\/p>\n<p>[0] \u5206\u7ea7\u8ba4\u8bc1(\u5982 PG-13 \/ R \/ TV-MA)<br \/>\n[1] \u4e0a\u6620\u65e5\u671f(release)<br \/>\n[2] \u7c7b\u578b\u6807\u7b7e(genres)<br \/>\n[3] \u65f6\u957f(runtime)<br \/>\n[4] \u5bfc\u6f14\u3001\u7f16\u5267\u7b49\u5176\u4ed6\u4fe1\u606f<\/p>\n<p>\u5173\u952e\u5728\u4e8e:\u4e0d\u662f\u6bcf\u90e8\u7535\u5f71\u90fd\u6709\u5206\u7ea7\u8ba4\u8bc1\u3002<\/p>\n<ul>\n<li>\u6709\u5206\u7ea7\u7684\u7535\u5f71:span[2] &#061; \u4e0a\u6620\u65e5\u671f \u2705,span[3] &#061; \u6807\u7b7e \u2705,span[4] &#061; \u65f6\u957f \u2705<\/li>\n<li>\u6ca1\u6709\u5206\u7ea7\u7684\u7535\u5f71:\u6574\u4e2a\u5e8f\u5217\u524d\u79fb\u4e00\u4f4d,span[2] \u53d8\u6210\u4e86\u6807\u7b7e,span[3] \u53d8\u6210\u4e86\u65f6\u957f,span[4] \u53ef\u80fd\u662f\u522b\u7684\u4e1c\u897f \u274c<\/li>\n<\/ul>\n<p>\u4f4d\u7f6e\u7d22\u5f15\u4e00\u65e6\u9519\u4f4d,\u53d6\u5230\u7684\u8981\u4e48\u662f\u9519\u7684\u5b57\u6bb5,\u8981\u4e48\u662f\u7a7a\u5b57\u7b26\u4e32\u3002\u8fd9\u5c31\u662f&#034;\u90e8\u5206\u7535\u5f71\u4fe1\u606f\u7a7a\u767d\/\u9519\u4f4d&#034;\u7684\u6839\u56e0\u3002<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4:\u4f4d\u7f6e\u7d22\u5f15\u628a&#034;\u7ed3\u6784\u5047\u8bbe&#034;\u5199\u6b7b\u4e86\u3002\u5b83\u5047\u8bbe&#034;\u4e0a\u6620\u65e5\u671f\u6c38\u8fdc\u662f\u7b2c 2 \u4e2a span&#034;,\u4f46\u8fd9\u4e2a\u5047\u8bbe\u5728\u6ca1\u6709\u5206\u7ea7\u7684\u7535\u5f71\u4e0a\u4e0d\u6210\u7acb\u3002<\/p>\n<h4>3.4 \u6539\u8fdb\u65b9\u6848:\u7528 &#064;class \u8bed\u4e49\u5b9a\u4f4d<\/h4>\n<p>\u628a\u4f4d\u7f6e\u7d22\u5f15\u6362\u6210 &#064;class \u5c5e\u6027\u5b9a\u4f4d:<\/p>\n<p><span class=\"token comment\"># \u4e0a\u6620\u65e5\u671f<\/span><br \/>\nmovie_data <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[&#064;class &#061; &#034;release&#034;]\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6807\u7b7e<\/span><br \/>\nmovie_tags <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[&#064;class &#061; &#034;genres&#034;]\/a\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u65f6\u957f<\/span><br \/>\nmovie_cost_times <span class=\"token operator\">&#061;<\/span> movie_doc<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/div[2]\/section\/div[1]\/div\/span[&#064;class &#061; &#034;runtime&#034;]\/text()&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5bf9\u6bd4\u4e00\u4e0b:<\/p>\n<table>\n<tr>\u5b57\u6bb5\u6539\u8fdb\u524d(\u4f4d\u7f6e\u7d22\u5f15)\u6539\u8fdb\u540e(class \u5b9a\u4f4d)<\/tr>\n<tbody>\n<tr>\n<td>\u4e0a\u6620\u65e5\u671f<\/td>\n<td>div\/span[2]\/text()<\/td>\n<td>div\/span[&#064;class&#061;&#034;release&#034;]\/text()<\/td>\n<\/tr>\n<tr>\n<td>\u6807\u7b7e<\/td>\n<td>div\/span[3]\/a\/text()<\/td>\n<td>div\/span[&#064;class&#061;&#034;genres&#034;]\/a\/text()<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u957f<\/td>\n<td>div\/span[4]\/text()<\/td>\n<td>div\/span[&#064;class&#061;&#034;runtime&#034;]\/text()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e3a\u4ec0\u4e48 class \u5b9a\u4f4d\u66f4\u7a33?<\/p>\n<ul>\n<li>span[2] \u8868\u793a&#034;\u7236\u8282\u70b9\u4e0b\u7b2c 2 \u4e2a span&#034;,\u4f9d\u8d56\u5144\u5f1f\u8282\u70b9\u7684\u6570\u91cf\u548c\u987a\u5e8f<\/li>\n<li>span[&#064;class&#061;&#034;release&#034;] \u8868\u793a&#034;\u7236\u8282\u70b9\u4e0b class \u4e3a release \u7684\u90a3\u4e2a span&#034;,\u4f9d\u8d56\u8bed\u4e49,\u4e0d\u4f9d\u8d56\u4f4d\u7f6e<\/li>\n<\/ul>\n<p>\u53ea\u8981 TMDB \u4e0d\u6539\u53d8\u5b57\u6bb5\u7684 class \u540d,\u65e0\u8bba\u524d\u9762\u6709\u6ca1\u6709\u5206\u7ea7,\u65e0\u8bba\u987a\u5e8f\u600e\u4e48\u53d8,\u90fd\u80fd\u7cbe\u786e\u547d\u4e2d\u3002\u518d\u6b21\u8fd0\u884c\u540e,\u7a7a\u767d\u5b57\u6bb5\u7684\u95ee\u9898\u6d88\u5931\u3002<\/p>\n<h4>3.5 \u5f15\u7533:XPath \u5b9a\u4f4d\u65b9\u5f0f\u7684\u7a33\u5b9a\u6027\u4f18\u5148\u7ea7<\/h4>\n<p>\u6309\u7a33\u5b9a\u6027\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f:<\/p>\n<li>&#064;id &#043; &#064;class \u8bed\u4e49\u5b9a\u4f4d \u2190 \u6700\u7a33,\u63a8\u8350<\/li>\n<li>&#064;id &#043; \u5c42\u7ea7\u7ed3\u6784\u5b9a\u4f4d:\/\/*[&#064;id&#061;&#034;original_header&#034;]\/&#8230;\/h2\/a\/text()<\/li>\n<li>\u6587\u672c\u5185\u5bb9\u5b9a\u4f4d:\/\/span[text()&#061;&#034;Runtime&#034;]\/following-sibling::span\/text()<\/li>\n<li>\u7eaf\u4f4d\u7f6e\u7d22\u5f15:div[2]\/span[3] \u2190 \u6700\u8106,\u5bb9\u6613\u7ffb\u8f66<\/li>\n<p>\u4e00\u53e5\u8bdd\u539f\u5219:\u80fd\u9760&#034;\u5c5e\u6027&#034;\u548c&#034;\u8bed\u4e49&#034;\u5b9a\u4f4d\u7684,\u5c31\u522b\u9760&#034;\u4f4d\u7f6e&#034;\u5b9a\u4f4d\u3002\u4f4d\u7f6e\u7d22\u5f15\u63cf\u8ff0\u7684\u662f&#034;\u5b83\u5728\u7b2c\u51e0\u4e2a&#034;,\u8bed\u4e49\u5b9a\u4f4d\u63cf\u8ff0\u7684\u662f&#034;\u6211\u8981\u4ec0\u4e48&#034;\u2014\u2014\u540e\u8005\u624d\u662f\u9875\u9762\u7ed3\u6784\u548c\u5b57\u6bb5\u8bed\u4e49\u4e4b\u95f4\u7684\u7a33\u5b9a\u5951\u7ea6\u3002<\/p>\n<h4>3.6 \u76f8\u540c\u601d\u8def\u53ef\u4ee5\u7ee7\u7eed\u4f18\u5316\u7684\u5730\u65b9<\/h4>\n<p>\u699c\u5355\u5217\u8868\u9879\u7684\u9009\u62e9\u5668\u4e5f\u662f\u9760\u4e00\u4e32\u957f\u957f\u7684 class:<\/p>\n<p>movies_list <span class=\"token operator\">&#061;<\/span> document<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/*[&#064;class&#061;&#034;w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm transition-colors hover:border-gray-300&#034;]&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u7c7b Tailwind \u751f\u6210\u7684 class \u7ec4\u5408,TMDB \u6539\u7248\u6837\u5f0f\u65f6\u5bb9\u6613\u6574\u4f53\u5931\u6548\u3002\u53ef\u4ee5\u7528\u66f4\u7a33\u5b9a\u7684\u7ed3\u6784\u7279\u5f81:<\/p>\n<p><span class=\"token comment\"># \u6293\u6240\u6709\u6307\u5411 \/movie\/ \u7684\u94fe\u63a5,\u518d\u56de\u6eaf\u7236\u7ea7\u5361\u7247<\/span><br \/>\nmovies_list <span class=\"token operator\">&#061;<\/span> document<span class=\"token punctuation\">.<\/span>xpath<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\/\/a[contains(&#064;href, &#034;\/movie\/&#034;)]&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h3>\u56db\u3001\u6570\u636e\u4fdd\u5b58(CSV)<\/h3>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">save_all_movies<\/span><span class=\"token punctuation\">(<\/span>all_movies<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">with<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span>MOVIE_LIST_FILE<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;w&#039;<\/span><span class=\"token punctuation\">,<\/span> encoding<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;UTF-8&#039;<\/span><span class=\"token punctuation\">,<\/span> newline<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> csvfile<span class=\"token punctuation\">:<\/span><br \/>\n        writer <span class=\"token operator\">&#061;<\/span> csv<span class=\"token punctuation\">.<\/span>DictWriter<span class=\"token punctuation\">(<\/span>csvfile<span class=\"token punctuation\">,<\/span> fieldnames<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;\u7535\u5f71\u540d&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u5e74\u4efd&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u4e0a\u6620\u65e5\u671f&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u65f6\u957f&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u6807\u7b7e&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u5206\u6570&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;\u8bed\u8a00&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        writer<span class=\"token punctuation\">.<\/span>writeheader<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        writer<span class=\"token punctuation\">.<\/span>writerows<span class=\"token punctuation\">(<\/span>all_movies<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u51e0\u4e2a\u7ec6\u8282:<\/p>\n<ul>\n<li>encoding&#061;&#039;UTF-8&#039;:\u4e2d\u6587\u5fc5\u987b\u6307\u5b9a,\u5426\u5219 Windows \u4e0b\u9ed8\u8ba4 GBK \u4f1a\u4e71\u7801<\/li>\n<li>newline&#061;&#039;&#039;:\u9632\u6b62 Windows \u4e0b\u6bcf\u884c\u4e4b\u95f4\u591a\u51fa\u7a7a\u884c<\/li>\n<li>DictWriter:\u6309\u5b57\u5178\u952e\u5199\u5165,fieldnames \u987a\u5e8f\u51b3\u5b9a\u5217\u987a\u5e8f<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e94\u3001\u53ef\u7ee7\u7eed\u4f18\u5316\u70b9<\/h3>\n<h4>1. \u5b57\u7b26\u4e32\u62fc\u63a5\u8868\u5355\u53c2\u6570\u4e0d\u4f18\u96c5<\/h4>\n<p>data <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;air_date.gte&#061;&amp;&#8230;&amp;page&#061;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>page_num<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&amp;&#8230;&#034;<\/span><\/span><\/p>\n<p>\u6539\u8fdb:\u7528\u5b57\u5178\u8ba9 requests \u81ea\u52a8\u7f16\u7801:<\/p>\n<p>data <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;sort_by&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;vote_average.desc&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;vote_count.gte&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">300<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;page&#034;<\/span><span class=\"token punctuation\">:<\/span> page_num<span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\nresponse <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> data<span class=\"token operator\">&#061;<\/span>data<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>2. \u6ca1\u6709\u5f02\u5e38\u5904\u7406<\/h4>\n<p>\u5355\u4e2a\u8be6\u60c5\u9875\u8bf7\u6c42\u5931\u8d25(\u8d85\u65f6\u3001404)\u4f1a\u76f4\u63a5\u4e2d\u65ad\u6574\u4e2a\u722c\u866b\u3002\u5efa\u8bae:<\/p>\n<p><span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    movie_response <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>movie_info_url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">15<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    movie_response<span class=\"token punctuation\">.<\/span>raise_for_status<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">except<\/span> requests<span class=\"token punctuation\">.<\/span>RequestException <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u8bf7\u6c42\u5931\u8d25: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>movie_info_url<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">, \u539f\u56e0: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>\u8c03\u7528\u5904\u8fc7\u6ee4\u6389 None \u518d\u4fdd\u5b58\u3002<\/p>\n<h4>3. \u7f3a\u5c11\u8bf7\u6c42\u95f4\u9694,\u5bb9\u6613\u88ab\u5c01<\/h4>\n<p>\u8fde\u7eed 5 \u9875 \u00d7 \u6bcf\u9875 ~20 \u90e8\u7535\u5f71 &#061; \u4e0a\u767e\u6b21\u8bf7\u6c42\u3002\u5efa\u8bae\u52a0:<\/p>\n<p><span class=\"token keyword\">import<\/span> time<span class=\"token punctuation\">,<\/span> random<br \/>\ntime<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span>random<span class=\"token punctuation\">.<\/span>uniform<span class=\"token punctuation\">(<\/span><span class=\"token number\">0.5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1.5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>4. \u5b57\u6bb5\u62bd\u53d6\u8fc7\u6563,\u53ef\u4ee5\u62bd\u6210\u914d\u7f6e<\/h4>\n<p>\u73b0\u5728\u6bcf\u52a0\u4e00\u4e2a\u5b57\u6bb5\u90fd\u8981\u6539\u4e09\u5904(\u5b9a\u4e49\u3001xpath\u3001dict)\u3002\u5efa\u8bae\u7528\u5217\u8868\u914d\u7f6e:<\/p>\n<p>FIELDS <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7535\u5f71\u540d&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/&#8230;\/h2\/a\/text()&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;first&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5e74\u4efd&#034;<\/span><span class=\"token punctuation\">,<\/span>   <span class=\"token string\">&#039;\/\/*[&#064;id&#061;&#034;original_header&#034;]\/&#8230;\/h2\/span\/text()&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;first&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><\/p>\n<hr \/>\n<h3>\u516d\u3001\u672c\u9879\u76ee\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e32\u8054<\/h3>\n<table>\n<tr>\u73af\u8282\u7528\u5230\u7684\u77e5\u8bc6<\/tr>\n<tbody>\n<tr>\n<td>\u53d1\u8bf7\u6c42<\/td>\n<td>requests.get \/ post\u3001headers \u4f2a\u88c5\u3001timeout<\/td>\n<\/tr>\n<tr>\n<td>\u62ff HTML<\/td>\n<td>lxml.html.fromstring<\/td>\n<\/tr>\n<tr>\n<td>\u5b9a\u4f4d\u5143\u7d20<\/td>\n<td>XPath \u8bed\u6cd5(\/\/\u3001&#064;id\u3001&#064;class\u3001text()\u3001contains())<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u6e05\u6d17<\/td>\n<td>strip()\u3001\u7a7a\u5217\u8868\u515c\u5e95\u3001&#039;,&#039;.join()<\/td>\n<\/tr>\n<tr>\n<td>\u5199\u6587\u4ef6<\/td>\n<td>csv.DictWriter\u3001encoding&#061;&#039;UTF-8&#039;\u3001newline&#061;&#039;&#039;<\/td>\n<\/tr>\n<tr>\n<td>\u6d41\u7a0b\u63a7\u5236<\/td>\n<td>for \u5faa\u73af\u5206\u9875\u3001\u5b57\u5178\u7ec4\u88c5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<p>\u8fd9\u4e2a\u6848\u4f8b\u867d\u5c0f,\u4f46\u628a\u722c\u866b\u7684\u5b8c\u6574\u94fe\u8def(\u8bf7\u6c42 \u2192 \u89e3\u6790 \u2192 \u6e05\u6d17 \u2192 \u5b58\u50a8)\u8d70\u4e86\u4e00\u904d\u3002<\/p>\n<p>\u672c\u6b21\u6539\u8fdb\u6700\u5927\u7684\u6536\u83b7\u662f:XPath \u5b9a\u4f4d\u5e94\u5f53\u5c3d\u91cf\u4f9d\u8d56&#034;\u8bed\u4e49\u5c5e\u6027(class\/id)\u201c,\u800c\u4e0d\u662f&#034;\u4f4d\u7f6e\u7d22\u5f15\u201d\u3002<\/p>\n<ul>\n<li>\u521d\u59cb\u7248\u672c\u7528 span[2] \/ span[3] \/ span[4] \u5b9a\u4f4d,\u5728\u7ed3\u6784\u4e00\u81f4\u7684\u9875\u9762\u4e0a\u52c9\u5f3a\u80fd\u7528<\/li>\n<li>\u4f46 TMDB \u8be6\u60c5\u9875\u5e76\u975e\u6240\u6709\u7535\u5f71\u90fd\u6709\u5206\u7ea7\u8ba4\u8bc1,\u5bfc\u81f4 span \u5e8f\u5217\u9519\u4f4d<\/li>\n<li>\u4e00\u9519\u4f4d,\u4f4d\u7f6e\u7d22\u5f15\u53d6\u5230\u7684\u5c31\u662f\u9519\u8bef\u5b57\u6bb5\u6216\u7a7a\u5b57\u7b26\u4e32,\u4e8e\u662f\u51fa\u73b0&#034;\u90e8\u5206\u7535\u5f71\u4fe1\u606f\u7a7a\u767d&#034;<\/li>\n<li>\u6362\u6210 span[&#064;class&#061;&#034;release&#034;] \u8fd9\u79cd\u8bed\u4e49\u5b9a\u4f4d\u540e,\u65e0\u8bba\u6709\u6ca1\u6709\u5206\u7ea7\u3001\u987a\u5e8f\u600e\u4e48\u53d8,\u90fd\u80fd\u7a33\u5b9a\u547d\u4e2d<\/li>\n<\/ul>\n<p>\u4f4d\u7f6e\u7d22\u5f15\u662f\u8106\u5f31\u7684,\u8bed\u4e49\u5b9a\u4f4d\u624d\u662f\u7a33\u5b9a\u7684\u2014\u2014\u8fd9\u662f\u672c\u6b21\u8e29\u5751\u6700\u6838\u5fc3\u7684\u53cd\u601d\u3002<\/p>\n<p>\u540e\u7eed\u53ef\u4ee5\u4ece\u4e09\u4e2a\u65b9\u5411\u7ee7\u7eed\u6df1\u5316:<\/p>\n<li>\u5065\u58ee\u6027:\u5f02\u5e38\u6355\u83b7\u3001\u91cd\u8bd5\u673a\u5236\u3001\u9650\u901f<\/li>\n<li>\u6269\u5c55\u6027:\u5b57\u6bb5\u914d\u7f6e\u5316\u3001XPath \u9009\u62e9\u5668\u4ece\u5916\u90e8\u914d\u7f6e\u8bfb\u53d6<\/li>\n<li>\u6301\u4e45\u5316:\u4ece CSV \u5347\u7ea7\u5230 SQLite \/ MySQL,\u4fbf\u4e8e\u540e\u7eed\u67e5\u8be2\u548c\u589e\u91cf\u66f4\u65b0<\/li>\n<hr \/>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3: \u722c\u866b\u7684\u672c\u8d28,\u662f&#034;\u7528\u7a0b\u5e8f\u6a21\u62df\u4eba\u7c7b\u6d4f\u89c8\u7f51\u9875\u7684\u884c\u4e3a,\u518d\u628a\u7ed3\u6784\u5316\u7684\u4fe1\u606f\u63d0\u53d6\u51fa\u6765&#034;\u3002 XPath \u7684\u7cbe\u9ad3,\u662f&#034;\u7528\u8bed\u4e49\u5c5e\u6027\u63cf\u8ff0\u4f60\u8981\u4ec0\u4e48&#034;,\u800c\u4e0d\u662f&#034;\u7528\u4f4d\u7f6e\u7d22\u5f15\u544a\u8bc9\u7a0b\u5e8f\u5b83\u6392\u7b2c\u51e0&#034;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2a\u4eba\u4e3b\u9875&#xff1a;&gt; for_ever_love__  \u6211\u60f3\u5b66python\u4e86  iOS\u9879\u76ee\u603b\u7ed3\u5927\u5168  iOS UI &lt; \u6587\u7ae0\u76ee\u5f55\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3\u4e00\u3001\u9879\u76ee\u6982\u8ff0\u4e8c\u3001\u6838\u5fc3\u6a21\u5757\u62c6\u89e31. \u8bf7\u6c42\u5934\u6784\u9020(\u53cd\u722c\u57fa\u7840)2. \u699c\u5355\u6570\u636e\u83b7\u53d6(\u5206\u9875\u5904\u7406)3. \u8be6\u60c5\u9875\u89e3\u6790(XPath)\u4e09\u3001\u95ee\u9898\u53d1\u73b0\u4e0e\u6539\u8fdb:\u4ece\u4f4d\u7f6e\u7d22\u5f15\u5230 class \u8bed\u4e49\u5b9a\u4f4d3.1 \u521d\u59cb\u7248<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4027,1680,330,81,677],"topic":[],"class_list":["post-111867","post","type-post","status-publish","format-standard","hentry","category-server","tag-cocoa","tag-ios","tag-macos","tag-python","tag-677"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/111867.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e2a\u4eba\u4e3b\u9875&#xff1a;&gt; for_ever_love__ \u6211\u60f3\u5b66python\u4e86 iOS\u9879\u76ee\u603b\u7ed3\u5927\u5168 iOS UI &lt; \u6587\u7ae0\u76ee\u5f55\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3\u4e00\u3001\u9879\u76ee\u6982\u8ff0\u4e8c\u3001\u6838\u5fc3\u6a21\u5757\u62c6\u89e31. \u8bf7\u6c42\u5934\u6784\u9020(\u53cd\u722c\u57fa\u7840)2. \u699c\u5355\u6570\u636e\u83b7\u53d6(\u5206\u9875\u5904\u7406)3. \u8be6\u60c5\u9875\u89e3\u6790(XPath)\u4e09\u3001\u95ee\u9898\u53d1\u73b0\u4e0e\u6539\u8fdb:\u4ece\u4f4d\u7f6e\u7d22\u5f15\u5230 class \u8bed\u4e49\u5b9a\u4f4d3.1 \u521d\u59cb\u7248\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/111867.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T17:16:54+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111867.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/111867.html\",\"name\":\"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-01T17:16:54+00:00\",\"dateModified\":\"2026-10-01T17:16:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/111867.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/111867.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111867.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/111867.html","og_locale":"zh_CN","og_type":"article","og_title":"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e2a\u4eba\u4e3b\u9875&#xff1a;&gt; for_ever_love__ \u6211\u60f3\u5b66python\u4e86 iOS\u9879\u76ee\u603b\u7ed3\u5927\u5168 iOS UI &lt; \u6587\u7ae0\u76ee\u5f55\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3\u4e00\u3001\u9879\u76ee\u6982\u8ff0\u4e8c\u3001\u6838\u5fc3\u6a21\u5757\u62c6\u89e31. \u8bf7\u6c42\u5934\u6784\u9020(\u53cd\u722c\u57fa\u7840)2. \u699c\u5355\u6570\u636e\u83b7\u53d6(\u5206\u9875\u5904\u7406)3. \u8be6\u60c5\u9875\u89e3\u6790(XPath)\u4e09\u3001\u95ee\u9898\u53d1\u73b0\u4e0e\u6539\u8fdb:\u4ece\u4f4d\u7f6e\u7d22\u5f15\u5230 class \u8bed\u4e49\u5b9a\u4f4d3.1 \u521d\u59cb\u7248","og_url":"https:\/\/www.wsisp.com\/helps\/111867.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-01T17:16:54+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/111867.html","url":"https:\/\/www.wsisp.com\/helps\/111867.html","name":"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-01T17:16:54+00:00","dateModified":"2026-10-01T17:16:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/111867.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/111867.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/111867.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u722c\u866b\u9879\u76ee: \u83b7\u53d6\u9ad8\u5206\u7535\u5f71\u7684\u6570\u636e\u603b\u7ed3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=111867"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111867\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=111867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=111867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=111867"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=111867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}