{"id":931129,"date":"2024-12-26T17:30:46","date_gmt":"2024-12-26T09:30:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/931129.html"},"modified":"2024-12-26T17:30:48","modified_gmt":"2024-12-26T09:30:48","slug":"python%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8html","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/931129.html","title":{"rendered":"python\u5982\u4f55\u4f7f\u7528html"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065553\/f32b70b1-99cf-4292-9329-b0750a72d8fc.webp\" alt=\"python\u5982\u4f55\u4f7f\u7528html\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u4e0eHTML\u8fdb\u884c\u4ea4\u4e92\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5e93\u5982BeautifulSoup\u89e3\u6790HTML\u3001\u4f7f\u7528Flask\u6216Django\u7b49\u6846\u67b6\u751f\u6210\u548c\u5904\u7406HTML\u3001\u901a\u8fc7Selenium\u81ea\u52a8\u5316\u5904\u7406\u7f51\u9875\u3002<\/strong>\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u5176\u72ec\u7279\u7684\u7528\u9014\u548c\u9002\u7528\u573a\u666f\u3002\u4f7f\u7528BeautifulSoup\u89e3\u6790HTML\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u7f51\u9875\u6293\u53d6\u6280\u672f\uff0c\u5b83\u53ef\u4ee5\u8ba9\u4f60\u63d0\u53d6\u548c\u64cd\u4f5cHTML\u6587\u6863\u4e2d\u7684\u6570\u636e\u3002Flask\u548cDjango\u662f\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7684\u6846\u67b6\uff0c\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u4f60\u751f\u6210\u52a8\u6001HTML\u9875\u9762\u3002Selenium\u5219\u7528\u4e8e\u81ea\u52a8\u5316\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7528\u4e8e\u6d4b\u8bd5\u548c\u64cd\u4f5c\u7f51\u9875\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528BeautifulSoup\u89e3\u6790HTML<\/p>\n<\/p>\n<p><p>BeautifulSoup\u662f\u4e00\u4e2a\u7528\u4e8e\u89e3\u6790HTML\u548cXML\u6587\u6863\u7684Python\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86Pythonic\u7684\u65b9\u5f0f\u6765\u63d0\u53d6\u548c\u64cd\u4f5cHTML\u6587\u6863\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u5bfc\u5165BeautifulSoup<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5BeautifulSoup\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7pip\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install beautifulsoup4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u89e3\u6790HTML\u6587\u6863<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4f7f\u7528BeautifulSoup\u89e3\u6790HTML\u6587\u6863\uff0c\u63d0\u53d6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">html_doc = &quot;&quot;&quot;<\/p>\n<p>&lt;html&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;title&gt;The Dormouse&#39;s story&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;p class=&quot;title&quot;&gt;&lt;b&gt;The Dormouse&#39;s story&lt;\/b&gt;&lt;\/p&gt;<\/p>\n<p>    &lt;p class=&quot;story&quot;&gt;Once upon a time there were three little sisters; and their names were<\/p>\n<p>        &lt;a href=&quot;http:\/\/example.com\/elsie&quot; class=&quot;sister&quot; id=&quot;link1&quot;&gt;Elsie&lt;\/a&gt;,<\/p>\n<p>        &lt;a href=&quot;http:\/\/example.com\/lacie&quot; class=&quot;sister&quot; id=&quot;link2&quot;&gt;Lacie&lt;\/a&gt; and<\/p>\n<p>        &lt;a href=&quot;http:\/\/example.com\/tillie&quot; class=&quot;sister&quot; id=&quot;link3&quot;&gt;Tillie&lt;\/a&gt;;<\/p>\n<p>        and they lived at the bottom of a well.&lt;\/p&gt;<\/p>\n<p>    &lt;p class=&quot;story&quot;&gt;...&lt;\/p&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<p>soup = BeautifulSoup(html_doc, &#39;html.parser&#39;)<\/p>\n<h2><strong>\u63d0\u53d6\u6240\u6709\u94fe\u63a5<\/strong><\/h2>\n<p>links = soup.find_all(&#39;a&#39;)<\/p>\n<p>for link in links:<\/p>\n<p>    print(link.get(&#39;href&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u63d0\u53d6\u548c\u64cd\u4f5c\u6570\u636e<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7BeautifulSoup\uff0c\u4f60\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u627e\u548c\u64cd\u4f5cHTML\u4e2d\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u67e5\u627e\u6240\u6709\u7684\u94fe\u63a5\u3001\u7279\u5b9a\u6807\u7b7e\u7684\u5185\u5bb9\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u67e5\u627e\u7279\u5b9aID\u7684\u5143\u7d20<\/p>\n<p>link1 = soup.find(id=&quot;link1&quot;)<\/p>\n<p>print(link1.string)<\/p>\n<h2><strong>\u67e5\u627e\u7279\u5b9a\u7c7b\u540d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>titles = soup.find_all(&#39;p&#39;, class_=&#39;title&#39;)<\/p>\n<p>for title in titles:<\/p>\n<p>    print(title.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>BeautifulSoup\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5b83\u7684\u7075\u6d3b\u6027\u548c\u7b80\u6d01\u6027\uff0c\u9002\u5408\u7528\u4e8e\u5404\u79cdHTML\u6587\u6863\u7684\u89e3\u6790\u548c\u6570\u636e\u63d0\u53d6\u4efb\u52a1\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Flask\u751f\u6210\u548c\u5904\u7406HTML<\/p>\n<\/p>\n<p><p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Python Web\u6846\u67b6\uff0c\u5b83\u5141\u8bb8\u4f60\u5feb\u901f\u6784\u5efaWeb\u5e94\u7528\u548cAPI\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u8bbe\u7f6eFlask<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u901a\u8fc7pip\u5b89\u88c5Flask\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install Flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Flask\u5e94\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, render_template<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/&#39;)<\/p>\n<p>def home():<\/p>\n<p>    return render_template(&#39;index.html&#39;)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u6a21\u677f\u5f15\u64ce\u751f\u6210HTML<\/li>\n<\/ol>\n<p><p>Flask\u4f7f\u7528Jinja2\u6a21\u677f\u5f15\u64ce\u6765\u751f\u6210HTML\u9875\u9762\u3002\u4f60\u53ef\u4ee5\u5728<code>templates<\/code>\u76ee\u5f55\u4e2d\u521b\u5efaHTML\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u6a21\u677f\u8bed\u6cd5\u6765\u52a8\u6001\u751f\u6210\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-html\">&lt;!-- templates\/index.html --&gt;<\/p>\n<p>&lt;!DOCTYPE html&gt;<\/p>\n<p>&lt;html lang=&quot;en&quot;&gt;<\/p>\n<p>&lt;head&gt;<\/p>\n<p>    &lt;meta charset=&quot;UTF-8&quot;&gt;<\/p>\n<p>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<\/p>\n<p>    &lt;title&gt;Flask Application&lt;\/title&gt;<\/p>\n<p>&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>    &lt;h1&gt;Welcome to Flask!&lt;\/h1&gt;<\/p>\n<p>    &lt;p&gt;This is a simple Flask application.&lt;\/p&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u5904\u7406\u7528\u6237\u8f93\u5165\u548c\u751f\u6210\u54cd\u5e94<\/li>\n<\/ol>\n<p><p>Flask\u53ef\u4ee5\u5904\u7406\u7528\u6237\u8f93\u5165\uff0c\u4f8b\u5982\u8868\u5355\u6570\u636e\uff0c\u5e76\u751f\u6210\u76f8\u5e94\u7684HTML\u54cd\u5e94\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import request<\/p>\n<p>@app.route(&#39;\/submit&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def submit():<\/p>\n<p>    user_input = request.form[&#39;input&#39;]<\/p>\n<p>    return f&quot;You submitted: {user_input}&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Flask\u7684\u4f18\u70b9\u5728\u4e8e\u5b83\u7684\u7b80\u5355\u6027\u548c\u7075\u6d3b\u6027\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u5f00\u53d1\u548c\u539f\u578b\u8bbe\u8ba1\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528Django\u5f00\u53d1\u590d\u6742\u7684Web\u5e94\u7528<\/p>\n<\/p>\n<p><p>Django\u662f\u4e00\u4e2a\u9ad8\u7ea7\u7684Python Web\u6846\u67b6\uff0c\u9002\u5408\u5f00\u53d1\u590d\u6742\u548c\u5927\u578bWeb\u5e94\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u521b\u5efaDjango\u9879\u76ee<\/li>\n<\/ol>\n<p><p>\u5b89\u88c5Django\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install Django<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Django\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">django-admin startproject myproject<\/p>\n<p>cd myproject<\/p>\n<p>python manage.py startapp myapp<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u6a21\u677f\u7cfb\u7edf\u548c\u89c6\u56fe<\/li>\n<\/ol>\n<p><p>Django\u4e5f\u4f7f\u7528\u6a21\u677f\u7cfb\u7edf\u6765\u751f\u6210HTML\u3002\u4f60\u53ef\u4ee5\u5728<code>templates<\/code>\u76ee\u5f55\u4e2d\u521b\u5efa\u6a21\u677f\uff0c\u5e76\u5728\u89c6\u56fe\u4e2d\u6e32\u67d3\u5b83\u4eec\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># myapp\/views.py<\/p>\n<p>from django.shortcuts import render<\/p>\n<p>def index(request):<\/p>\n<p>    return render(request, &#39;index.html&#39;, context={})<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u5904\u7406\u8868\u5355\u548c\u6a21\u578b<\/li>\n<\/ol>\n<p><p>Django\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684ORM\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u6765\u5904\u7406\u6570\u636e\u5e93\u6a21\u578b\uff0c\u4ee5\u53ca\u8868\u5355\u5904\u7406\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># myapp\/models.py<\/p>\n<p>from django.db import models<\/p>\n<p>class Item(models.Model):<\/p>\n<p>    name = models.CharField(max_length=100)<\/p>\n<p>    description = models.TextField()<\/p>\n<h2><strong>myapp\/forms.py<\/strong><\/h2>\n<p>from django import forms<\/p>\n<p>class ItemForm(forms.ModelForm):<\/p>\n<p>    class Meta:<\/p>\n<p>        model = Item<\/p>\n<p>        fields = [&#39;name&#39;, &#39;description&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Django\u662f\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684\u6846\u67b6\uff0c\u9002\u5408\u4e8e\u9700\u8981\u590d\u6742\u6570\u636e\u5e93\u4ea4\u4e92\u548c\u7528\u6237\u7ba1\u7406\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528Selenium\u81ea\u52a8\u5316\u7f51\u9875\u64cd\u4f5c<\/p>\n<\/p>\n<p><p>Selenium\u662f\u4e00\u4e2a\u7528\u4e8e\u81ea\u52a8\u5316Web\u6d4f\u89c8\u5668\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u5e38\u7528\u4e8e\u6d4b\u8bd5\u548c\u7f51\u9875\u6293\u53d6\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u8bbe\u7f6eSelenium<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5Selenium\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install selenium<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd8\u9700\u8981\u4e0b\u8f7d\u5bf9\u5e94\u7684\u6d4f\u89c8\u5668\u9a71\u52a8\uff0c\u4f8b\u5982ChromeDriver\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u542f\u52a8\u6d4f\u89c8\u5668\u5e76\u8bbf\u95ee\u7f51\u9875<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528Selenium\u542f\u52a8\u6d4f\u89c8\u5668\uff0c\u5e76\u8bbf\u95ee\u7f51\u9875\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from selenium import webdriver<\/p>\n<p>driver = webdriver.Chrome(executable_path=&#39;\/path\/to\/chromedriver&#39;)<\/p>\n<p>driver.get(&#39;http:\/\/example.com&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u67e5\u627e\u5143\u7d20\u5e76\u6267\u884c\u64cd\u4f5c<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u901a\u8fc7Selenium\u67e5\u627e\u7f51\u9875\u4e2d\u7684\u5143\u7d20\uff0c\u5e76\u6267\u884c\u70b9\u51fb\u3001\u8f93\u5165\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u67e5\u627e\u8f93\u5165\u6846\u5e76\u8f93\u5165\u6587\u672c<\/p>\n<p>input_box = driver.find_element_by_name(&#39;q&#39;)<\/p>\n<p>input_box.send_keys(&#39;Python Selenium&#39;)<\/p>\n<h2><strong>\u67e5\u627e\u5e76\u70b9\u51fb\u6309\u94ae<\/strong><\/h2>\n<p>search_button = driver.find_element_by_name(&#39;btnK&#39;)<\/p>\n<p>search_button.click()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u83b7\u53d6\u7f51\u9875\u5185\u5bb9<\/li>\n<\/ol>\n<p><p>\u53ef\u4ee5\u4ece\u7f51\u9875\u4e2d\u83b7\u53d6\u5185\u5bb9\uff0c\u4f8b\u5982\u83b7\u53d6\u5f53\u524d\u9875\u9762\u7684HTML\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">page_source = driver.page_source<\/p>\n<p>print(page_source)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Selenium\u7684\u4f18\u52bf\u5728\u4e8e\u5176\u5f3a\u5927\u7684\u81ea\u52a8\u5316\u80fd\u529b\uff0c\u975e\u5e38\u9002\u5408\u6d4b\u8bd5Web\u5e94\u7528\u548c\u81ea\u52a8\u5316\u91cd\u590d\u6027\u4efb\u52a1\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u4e0d\u540c\u7684\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Python\u4e2d\u7075\u6d3b\u5730\u4f7f\u7528HTML\uff0c\u4ece\u89e3\u6790\u548c\u751f\u6210HTML\u5230\u81ea\u52a8\u5316\u6d4f\u89c8\u5668\u64cd\u4f5c\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u5e93\u6765\u6ee1\u8db3\u5404\u79cd\u9700\u6c42\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u7f51\u9875\u6293\u53d6\u4efb\u52a1\uff0c\u8fd8\u662f\u590d\u6742\u7684Web\u5e94\u7528\u5f00\u53d1\uff0cPython\u90fd\u6709\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u89e3\u6790\u548c\u5904\u7406HTML\u6587\u6863\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u89e3\u6790\u548c\u5904\u7406HTML\u6587\u6863\u901a\u5e38\u4f7f\u7528Beautiful Soup\u5e93\u3002\u8fd9\u4e2a\u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u63d0\u53d6\u6570\u636e\u5e76\u64cd\u4f5cHTML\u7ed3\u6784\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5Beautiful Soup\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5\uff1a<code>pip install beautifulsoup4<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7\u5bfc\u5165Beautiful Soup\u5e76\u4f7f\u7528<code>BeautifulSoup<\/code>\u7c7b\u6765\u52a0\u8f7dHTML\u6587\u6863\uff0c\u5c31\u80fd\u5f00\u59cb\u89e3\u6790\u4e86\u3002\u53ef\u4ee5\u4f7f\u7528CSS\u9009\u62e9\u5668\u6216\u5176\u4ed6\u65b9\u6cd5\u6765\u63d0\u53d6\u7279\u5b9a\u5143\u7d20\u548c\u6570\u636e\u3002<\/p>\n<p><strong>Python\u80fd\u5426\u751f\u6210\u52a8\u6001HTML\u9875\u9762\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u53ef\u4ee5\u751f\u6210\u52a8\u6001HTML\u9875\u9762\u3002\u4f7f\u7528Flask\u6216Django\u7b49Web\u6846\u67b6\uff0c\u53ef\u4ee5\u6839\u636e\u7528\u6237\u8bf7\u6c42\u751f\u6210\u52a8\u6001\u5185\u5bb9\u3002Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u6846\u67b6\uff0c\u975e\u5e38\u9002\u5408\u5c0f\u578b\u9879\u76ee\uff0c\u800cDjango\u5219\u9002\u5408\u5927\u578b\u5e94\u7528\u3002\u901a\u8fc7\u8fd9\u4e9b\u6846\u67b6\uff0c\u60a8\u53ef\u4ee5\u5c06HTML\u6a21\u677f\u4e0ePython\u4ee3\u7801\u7ed3\u5408\uff0c\u5b9e\u73b0\u52a8\u6001\u6570\u636e\u5c55\u793a\u548c\u4ea4\u4e92\u529f\u80fd\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u63d0\u53d6HTML\u4e2d\u7684\u7279\u5b9a\u4fe1\u606f\uff1f<\/strong><br \/>\u63d0\u53d6HTML\u4e2d\u7684\u7279\u5b9a\u4fe1\u606f\u53ef\u4ee5\u4f7f\u7528Beautiful Soup\u4e0erequests\u5e93\u7ed3\u5408\u3002\u9996\u5148\u4f7f\u7528requests\u5e93\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\uff0c\u7136\u540e\u5c06\u5185\u5bb9\u4f20\u9012\u7ed9Beautiful Soup\u8fdb\u884c\u89e3\u6790\u3002\u53ef\u4ee5\u4f7f\u7528<code>find<\/code>\u548c<code>find_all<\/code>\u65b9\u6cd5\u6765\u67e5\u627e\u7279\u5b9a\u6807\u7b7e\u6216\u7c7b\u540d\uff0c\u4ece\u800c\u63d0\u53d6\u6240\u9700\u7684\u4fe1\u606f\u3002\u7ed3\u5408\u6b63\u5219\u8868\u8fbe\u5f0f\u4e5f\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u53d6\u590d\u6742\u6a21\u5f0f\u7684\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u4e0eHTML\u8fdb\u884c\u4ea4\u4e92\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5e93\u5982BeautifulSoup\u89e3\u6790HTML\u3001 [&hellip;]","protected":false},"author":3,"featured_media":931136,"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\/931129"}],"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=931129"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/931129\/revisions"}],"predecessor-version":[{"id":931137,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/931129\/revisions\/931137"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/931136"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=931129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=931129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=931129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}