{"id":1155853,"date":"2025-01-13T18:08:52","date_gmt":"2025-01-13T10:08:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155853.html"},"modified":"2025-01-13T18:08:54","modified_gmt":"2025-01-13T10:08:54","slug":"python%e5%a6%82%e4%bd%95%e7%88%ac%e7%bd%91%e7%ab%99%e5%9c%b0%e5%9b%be","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155853.html","title":{"rendered":"python\u5982\u4f55\u722c\u7f51\u7ad9\u5730\u56fe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25194406\/93e97d03-3811-4fbe-90de-497eae043408.webp\" alt=\"python\u5982\u4f55\u722c\u7f51\u7ad9\u5730\u56fe\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u89e3\u6790\u7f51\u7ad9\u5730\u56feURL\u3001\u63d0\u53d6URL\u5217\u8868\u3001\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9\u3001\u89e3\u6790\u7f51\u9875\u5185\u5bb9\u3002<\/strong> \u5176\u4e2d\uff0c\u89e3\u6790\u7f51\u7ad9\u5730\u56feURL\u662f\u5173\u952e\u6b65\u9aa4\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u89e3\u6790\u7f51\u7ad9\u5730\u56feURL<\/h3>\n<\/p>\n<p><p>\u7f51\u7ad9\u5730\u56fe\u901a\u5e38\u662f\u4e00\u4e2aXML\u6587\u4ef6\uff0c\u5305\u542b\u4e86\u7f51\u7ad9\u4e0a\u6240\u6709\u9875\u9762\u7684URL\u3002\u8981\u89e3\u6790\u7f51\u7ad9\u5730\u56fe\uff0c\u9996\u5148\u9700\u8981\u83b7\u53d6\u8be5XML\u6587\u4ef6\u7684URL\u3002\u7f51\u7ad9\u5730\u56fe\u6587\u4ef6\u901a\u5e38\u547d\u540d\u4e3a<code>sitemap.xml<\/code>\uff0c\u5e76\u653e\u7f6e\u5728\u7f51\u7ad9\u7684\u6839\u76ee\u5f55\u4e0b\uff0c\u4f8b\u5982<code>https:\/\/example.com\/sitemap.xml<\/code>\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>requests<\/code>\u548c<code>xml.etree.ElementTree<\/code>\u6a21\u5757\u6765\u89e3\u6790\u8be5\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u901a\u8fc7<code>requests<\/code>\u6a21\u5757\u53d1\u9001HTTP GET\u8bf7\u6c42\u83b7\u53d6\u7f51\u7ad9\u5730\u56fe\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528<code>xml.etree.ElementTree<\/code>\u6a21\u5757\u89e3\u6790XML\u6587\u4ef6\uff0c\u4ece\u4e2d\u63d0\u53d6\u6240\u6709URL\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>import xml.etree.ElementTree as ET<\/p>\n<p>def fetch_sitemap(url):<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    if response.status_code == 200:<\/p>\n<p>        return response.content<\/p>\n<p>    else:<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se Exception(f&quot;Failed to fetch sitemap: {response.status_code}&quot;)<\/p>\n<p>def parse_sitemap(xml_content):<\/p>\n<p>    root = ET.fromstring(xml_content)<\/p>\n<p>    urls = []<\/p>\n<p>    for url in root.findall(&quot;.\/\/{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}url&quot;):<\/p>\n<p>        loc = url.find(&quot;{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}loc&quot;).text<\/p>\n<p>        urls.append(loc)<\/p>\n<p>    return urls<\/p>\n<p>sitemap_url = &quot;https:\/\/example.com\/sitemap.xml&quot;<\/p>\n<p>xml_content = fetch_sitemap(sitemap_url)<\/p>\n<p>urls = parse_sitemap(xml_content)<\/p>\n<p>print(urls)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u63d0\u53d6URL\u5217\u8868<\/h3>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u548c\u89e3\u6790\u7f51\u7ad9\u5730\u56fe\u540e\uff0c\u6211\u4eec\u4f1a\u5f97\u5230\u4e00\u4e2a\u5305\u542b\u6240\u6709\u9875\u9762URL\u7684\u5217\u8868\u3002\u6211\u4eec\u53ef\u4ee5\u5bf9\u8fd9\u4e9bURL\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u4f8b\u5982\uff0c\u8fc7\u6ee4\u51fa\u7279\u5b9a\u7c7b\u578b\u7684\u9875\u9762\uff0c\u6216\u8005\u53ea\u5904\u7406\u7279\u5b9a\u76ee\u5f55\u4e0b\u7684\u9875\u9762\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">filtered_urls = [url for url in urls if &#39;blog&#39; in url]<\/p>\n<p>print(filtered_urls)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528<code>requests<\/code>\u6a21\u5757\u8bf7\u6c42\u6bcf\u4e2aURL\u7684\u7f51\u9875\u5185\u5bb9\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u904d\u5386URL\u5217\u8868\uff0c\u5e76\u5bf9\u6bcf\u4e2aURL\u53d1\u9001HTTP GET\u8bf7\u6c42\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def fetch_page_content(url):<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    if response.status_code == 200:<\/p>\n<p>        return response.text<\/p>\n<p>    else:<\/p>\n<p>        print(f&quot;Failed to fetch page: {url}&quot;)<\/p>\n<p>        return None<\/p>\n<p>page_contents = []<\/p>\n<p>for url in filtered_urls:<\/p>\n<p>    content = fetch_page_content(url)<\/p>\n<p>    if content:<\/p>\n<p>        page_contents.append(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u89e3\u6790\u7f51\u9875\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>BeautifulSoup<\/code>\u7b49HTML\u89e3\u6790\u5e93\u6765\u89e3\u6790\u7f51\u9875\u5185\u5bb9\uff0c\u63d0\u53d6\u6211\u4eec\u9700\u8981\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u53d6\u9875\u9762\u7684\u6807\u9898\u3001\u6587\u7ae0\u5185\u5bb9\u3001\u56fe\u7247URL\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bs4 import BeautifulSoup<\/p>\n<p>def parse_page_content(html_content):<\/p>\n<p>    soup = BeautifulSoup(html_content, &#39;html.parser&#39;)<\/p>\n<p>    title = soup.find(&#39;title&#39;).text<\/p>\n<p>    body = soup.find(&#39;body&#39;).text<\/p>\n<p>    return {<\/p>\n<p>        &#39;title&#39;: title,<\/p>\n<p>        &#39;body&#39;: body<\/p>\n<p>    }<\/p>\n<p>parsed_pages = []<\/p>\n<p>for content in page_contents:<\/p>\n<p>    parsed_page = parse_page_content(content)<\/p>\n<p>    parsed_pages.append(parsed_page)<\/p>\n<p>for page in parsed_pages:<\/p>\n<p>    print(f&quot;Title: {page[&#39;title&#39;]}&quot;)<\/p>\n<p>    print(f&quot;Body: {page[&#39;body&#39;][:200]}...&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4fdd\u5b58\u63d0\u53d6\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u7f51\u9875\u5185\u5bb9\u7684\u89e3\u6790\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u63d0\u53d6\u5230\u7684\u4fe1\u606f\u4fdd\u5b58\u5230\u6587\u4ef6\u6216\u8005\u6570\u636e\u5e93\u4e2d\u3002\u8fd9\u91cc\u4ee5\u4fdd\u5b58\u5230CSV\u6587\u4ef6\u4e3a\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<p>def save_to_csv(parsed_pages, filename):<\/p>\n<p>    keys = parsed_pages[0].keys()<\/p>\n<p>    with open(filename, &#39;w&#39;, newline=&#39;&#39;) as output_file:<\/p>\n<p>        dict_writer = csv.DictWriter(output_file, fieldnames=keys)<\/p>\n<p>        dict_writer.writeheader()<\/p>\n<p>        dict_writer.writerows(parsed_pages)<\/p>\n<p>save_to_csv(parsed_pages, &#39;parsed_pages.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u9519\u8bef\u5904\u7406\u4e0e\u91cd\u8bd5\u673a\u5236<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\uff0c\u7f51\u7edc\u8bf7\u6c42\u53ef\u80fd\u4f1a\u5931\u8d25\uff0c\u89e3\u6790\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u9047\u5230\u683c\u5f0f\u4e0d\u6b63\u786e\u7684\u7f51\u9875\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u9519\u8bef\u5904\u7406\u548c\u91cd\u8bd5\u673a\u5236\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u5065\u58ee\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def fetch_page_content_with_retry(url, retries=3, delay=5):<\/p>\n<p>    for i in range(retries):<\/p>\n<p>        try:<\/p>\n<p>            response = requests.get(url, timeout=10)<\/p>\n<p>            if response.status_code == 200:<\/p>\n<p>                return response.text<\/p>\n<p>            else:<\/p>\n<p>                print(f&quot;Failed to fetch page: {url}, status code: {response.status_code}&quot;)<\/p>\n<p>        except requests.RequestException as e:<\/p>\n<p>            print(f&quot;Exception occurred: {e}&quot;)<\/p>\n<p>        time.sleep(delay)<\/p>\n<p>    return None<\/p>\n<p>page_contents = []<\/p>\n<p>for url in filtered_urls:<\/p>\n<p>    content = fetch_page_content_with_retry(url)<\/p>\n<p>    if content:<\/p>\n<p>        page_contents.append(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u5e76\u53d1\u8bf7\u6c42<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u722c\u53d6\u901f\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5e76\u53d1\u8bf7\u6c42\u3002Python\u7684<code>concurrent.futures<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u5e76\u53d1\u5de5\u5177\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>ThreadPoolExecutor<\/code>\u6765\u5e76\u53d1\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from concurrent.futures import ThreadPoolExecutor, as_completed<\/p>\n<p>def fetch_page_content_concurrent(urls):<\/p>\n<p>    page_contents = []<\/p>\n<p>    with ThreadPoolExecutor(max_workers=10) as executor:<\/p>\n<p>        future_to_url = {executor.submit(fetch_page_content_with_retry, url): url for url in urls}<\/p>\n<p>        for future in as_completed(future_to_url):<\/p>\n<p>            url = future_to_url[future]<\/p>\n<p>            try:<\/p>\n<p>                content = future.result()<\/p>\n<p>                if content:<\/p>\n<p>                    page_contents.append(content)<\/p>\n<p>            except Exception as e:<\/p>\n<p>                print(f&quot;Exception occurred for {url}: {e}&quot;)<\/p>\n<p>    return page_contents<\/p>\n<p>page_contents = fetch_page_content_concurrent(filtered_urls)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u6570\u636e\u6e05\u6d17\u548c\u89c4\u8303\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u63d0\u53d6\u7f51\u9875\u5185\u5bb9\u540e\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u4e0d\u89c4\u8303\u7684\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u5305\u542bHTML\u6807\u7b7e\u7684\u6587\u672c\u3001\u4e0d\u5b8c\u6574\u7684\u5185\u5bb9\u7b49\u3002\u6211\u4eec\u9700\u8981\u5bf9\u8fd9\u4e9b\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u89c4\u8303\u5316\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>def clean_text(text):<\/p>\n<p>    text = re.sub(r&#39;&lt;[^&gt;]+&gt;&#39;, &#39;&#39;, text)  # Remove HTML tags<\/p>\n<p>    text = re.sub(r&#39;\\s+&#39;, &#39; &#39;, text)  # Replace multiple whitespace with a single space<\/p>\n<p>    text = text.strip()<\/p>\n<p>    return text<\/p>\n<p>cleaned_pages = []<\/p>\n<p>for page in parsed_pages:<\/p>\n<p>    cleaned_page = {<\/p>\n<p>        &#39;title&#39;: clean_text(page[&#39;title&#39;]),<\/p>\n<p>        &#39;body&#39;: clean_text(page[&#39;body&#39;])<\/p>\n<p>    }<\/p>\n<p>    cleaned_pages.append(cleaned_page)<\/p>\n<p>for page in cleaned_pages:<\/p>\n<p>    print(f&quot;Title: {page[&#39;title&#39;]}&quot;)<\/p>\n<p>    print(f&quot;Body: {page[&#39;body&#39;][:200]}...&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u6269\u5c55\uff1a\u5904\u7406\u5206\u9875\u7f51\u7ad9\u5730\u56fe<\/h3>\n<\/p>\n<p><p>\u6709\u4e9b\u7f51\u7ad9\u5730\u56fe\u5305\u542b\u591a\u4e2a\u5206\u9875\uff08\u5b50\u7f51\u7ad9\u5730\u56fe\uff09\uff0c\u6211\u4eec\u9700\u8981\u9012\u5f52\u5904\u7406\u8fd9\u4e9b\u5206\u9875\u4ee5\u83b7\u53d6\u6240\u6709URL\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def parse_sitemap_recursive(xml_content):<\/p>\n<p>    root = ET.fromstring(xml_content)<\/p>\n<p>    urls = []<\/p>\n<p>    for sitemap in root.findall(&quot;.\/\/{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}sitemap&quot;):<\/p>\n<p>        loc = sitemap.find(&quot;{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}loc&quot;).text<\/p>\n<p>        child_sitemap_content = fetch_sitemap(loc)<\/p>\n<p>        urls.extend(parse_sitemap_recursive(child_sitemap_content))<\/p>\n<p>    for url in root.findall(&quot;.\/\/{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}url&quot;):<\/p>\n<p>        loc = url.find(&quot;{http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9}loc&quot;).text<\/p>\n<p>        urls.append(loc)<\/p>\n<p>    return urls<\/p>\n<p>sitemap_url = &quot;https:\/\/example.com\/sitemap.xml&quot;<\/p>\n<p>xml_content = fetch_sitemap(sitemap_url)<\/p>\n<p>all_urls = parse_sitemap_recursive(xml_content)<\/p>\n<p>print(all_urls)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u4f7f\u7528Python\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u7684\u5168\u8fc7\u7a0b\u3002\u603b\u7ed3\u8d77\u6765\uff0c\u6574\u4e2a\u8fc7\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u89e3\u6790\u7f51\u7ad9\u5730\u56feURL<\/strong>\uff1a\u83b7\u53d6\u5e76\u89e3\u6790\u7f51\u7ad9\u5730\u56fe\u6587\u4ef6\uff0c\u63d0\u53d6\u6240\u6709\u9875\u9762\u7684URL\u3002<\/li>\n<li><strong>\u63d0\u53d6URL\u5217\u8868<\/strong>\uff1a\u6839\u636e\u9700\u8981\u8fc7\u6ee4\u548c\u5904\u7406URL\u5217\u8868\u3002<\/li>\n<li><strong>\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9<\/strong>\uff1a\u4f7f\u7528<code>requests<\/code>\u6a21\u5757\u8bf7\u6c42\u6bcf\u4e2aURL\u7684\u7f51\u9875\u5185\u5bb9\u3002<\/li>\n<li><strong>\u89e3\u6790\u7f51\u9875\u5185\u5bb9<\/strong>\uff1a\u4f7f\u7528<code>BeautifulSoup<\/code>\u7b49\u89e3\u6790\u5e93\u89e3\u6790\u7f51\u9875\u5185\u5bb9\uff0c\u63d0\u53d6\u9700\u8981\u7684\u4fe1\u606f\u3002<\/li>\n<li><strong>\u4fdd\u5b58\u63d0\u53d6\u7ed3\u679c<\/strong>\uff1a\u5c06\u63d0\u53d6\u5230\u7684\u4fe1\u606f\u4fdd\u5b58\u5230\u6587\u4ef6\u6216\u6570\u636e\u5e93\u4e2d\u3002<\/li>\n<li><strong>\u9519\u8bef\u5904\u7406\u4e0e\u91cd\u8bd5\u673a\u5236<\/strong>\uff1a\u6dfb\u52a0\u9519\u8bef\u5904\u7406\u548c\u91cd\u8bd5\u673a\u5236\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u3002<\/li>\n<li><strong>\u5e76\u53d1\u8bf7\u6c42<\/strong>\uff1a\u4f7f\u7528<code>concurrent.futures<\/code>\u6a21\u5757\u63d0\u9ad8\u722c\u53d6\u901f\u5ea6\u3002<\/li>\n<li><strong>\u6570\u636e\u6e05\u6d17\u548c\u89c4\u8303\u5316<\/strong>\uff1a\u5bf9\u63d0\u53d6\u5230\u7684\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u89c4\u8303\u5316\u5904\u7406\u3002<\/li>\n<li><strong>\u5904\u7406\u5206\u9875\u7f51\u7ad9\u5730\u56fe<\/strong>\uff1a\u9012\u5f52\u5904\u7406\u5206\u9875\u7f51\u7ad9\u5730\u56fe\uff0c\u83b7\u53d6\u6240\u6709URL\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u9ad8\u6548\u5730\u722c\u53d6\u548c\u89e3\u6790\u7f51\u7ad9\u5730\u56fe\uff0c\u5e76\u63d0\u53d6\u6240\u9700\u7684\u7f51\u9875\u4fe1\u606f\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u83b7\u53d6\u7f51\u7ad9\u5730\u56fe\u7684URL\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u7f51\u7ad9\u7684\u6839\u76ee\u5f55\u6765\u83b7\u53d6\u7f51\u7ad9\u5730\u56fe\u7684URL\u3002\u5927\u591a\u6570\u7f51\u7ad9\u4f1a\u5728\u6839\u76ee\u5f55\u4e0b\u63d0\u4f9b\u4e00\u4e2a\u540d\u4e3a<code>sitemap.xml<\/code>\u7684\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165<code>https:\/\/example.com\/sitemap.xml<\/code>\u8fdb\u884c\u8bbf\u95ee\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u67e5\u770brobots.txt\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u901a\u5e38\u5305\u542b\u6307\u5411\u7f51\u7ad9\u5730\u56fe\u7684\u94fe\u63a5\uff0c\u4f8b\u5982<code>https:\/\/example.com\/robots.txt<\/code>\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u9700\u8981\u54ea\u4e9b\u5e93\uff1f<\/strong><br \/>\u5728\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u65f6\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u4e00\u4e9bPython\u5e93\uff0c\u5982<code>requests<\/code>\u6765\u53d1\u9001HTTP\u8bf7\u6c42\uff0c<code>BeautifulSoup<\/code>\u6216<code>lxml<\/code>\u6765\u89e3\u6790XML\u6587\u4ef6\u3002\u8fd9\u4e9b\u5e93\u80fd\u591f\u5e2e\u52a9\u60a8\u63d0\u53d6\u7f51\u7ad9\u5730\u56fe\u4e2d\u7684\u94fe\u63a5\u548c\u5176\u4ed6\u4fe1\u606f\u3002\u786e\u4fdd\u5728\u4f7f\u7528\u8fd9\u4e9b\u5e93\u4e4b\u524d\u901a\u8fc7<code>pip<\/code>\u5b89\u88c5\u5b83\u4eec\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u722c\u53d6\u5230\u7684XML\u7f51\u7ad9\u5730\u56fe\u6570\u636e\uff1f<\/strong><br \/>\u4e00\u65e6\u60a8\u6210\u529f\u722c\u53d6\u5230\u7f51\u7ad9\u5730\u56fe\u7684XML\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>BeautifulSoup<\/code>\u6216<code>xml.etree.ElementTree<\/code>\u7b49\u5e93\u89e3\u6790XML\u683c\u5f0f\u3002\u89e3\u6790\u540e\uff0c\u60a8\u53ef\u4ee5\u63d0\u53d6\u51fa\u6bcf\u4e2aURL\u3001\u6700\u540e\u4fee\u6539\u65f6\u95f4\u7b49\u4fe1\u606f\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728CSV\u6587\u4ef6\u3001\u6570\u636e\u5e93\u6216\u8005\u5176\u4ed6\u6570\u636e\u683c\u5f0f\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u548c\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u722c\u53d6\u7f51\u7ad9\u5730\u56fe\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u89e3\u6790\u7f51\u7ad9\u5730\u56feURL\u3001\u63d0\u53d6URL\u5217\u8868\u3001\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9\u3001\u89e3\u6790\u7f51\u9875\u5185\u5bb9\u3002 \u5176\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":1155858,"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\/1155853"}],"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=1155853"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155853\/revisions"}],"predecessor-version":[{"id":1155862,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155853\/revisions\/1155862"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1155858"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1155853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1155853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1155853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}