{"id":767,"date":"2025-01-05T22:54:07","date_gmt":"2025-01-05T14:54:07","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=767"},"modified":"2025-01-11T16:11:30","modified_gmt":"2025-01-11T08:11:30","slug":"python%e7%88%ac%e8%99%ab%e7%9a%84%e5%8e%9f%e7%90%86%e3%80%81%e5%b8%b8%e7%94%a8%e5%ba%93%e5%8f%8a%e5%ae%9e%e6%88%98%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/05\/python%e7%88%ac%e8%99%ab%e7%9a%84%e5%8e%9f%e7%90%86%e3%80%81%e5%b8%b8%e7%94%a8%e5%ba%93%e5%8f%8a%e5%ae%9e%e6%88%98%e6%a1%88%e4%be%8b\/","title":{"rendered":"\u6df1\u5165\u89e3\u6790 Python \u722c\u866b\uff1a\u539f\u7406\u3001\u5e38\u7528\u5e93\u4e0e\u5b9e\u6218\u6848\u4f8b"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Python \u722c\u866b\u662f\u5229\u7528\u7a0b\u5e8f\u6a21\u62df\u6d4f\u89c8\u5668\u7684\u884c\u4e3a\uff0c\u901a\u8fc7\u53d1\u9001 HTTP \u8bf7\u6c42\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u5e76\u89e3\u6790\u3001\u63d0\u53d6\u4fe1\u606f\u7684\u8fc7\u7a0b\u3002\u722c\u866b\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u91c7\u96c6\u3001\u7f51\u7ad9\u76d1\u63a7\u3001\u4fe1\u606f\u62bd\u53d6\u7b49\u5404\u79cd\u7528\u9014\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u722c\u866b\u539f\u7406<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u722c\u866b\u7684\u57fa\u672c\u5de5\u4f5c\u6d41\u7a0b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.1 <strong>\u53d1\u9001 HTTP \u8bf7\u6c42<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u722c\u866b\u7a0b\u5e8f\u901a\u8fc7\u53d1\u9001 HTTP \u8bf7\u6c42\u5411\u76ee\u6807\u7f51\u7ad9\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9\u3002\u5e38\u89c1\u7684 HTTP \u8bf7\u6c42\u65b9\u6cd5\u6709\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GET<\/strong>\uff1a\u8bf7\u6c42\u83b7\u53d6\u6570\u636e\uff08\u6700\u5e38\u7528\uff09\u3002<\/li>\n\n\n\n<li><strong>POST<\/strong>\uff1a\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\uff0c\u5e38\u7528\u4e8e\u63d0\u4ea4\u8868\u5355\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1.2 <strong>\u63a5\u6536\u54cd\u5e94\u6570\u636e<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u670d\u52a1\u5668\u54cd\u5e94\u8fd4\u56de\u7684\u5185\u5bb9\u53ef\u80fd\u662f HTML\u3001JSON\u3001XML \u7b49\u6570\u636e\u683c\u5f0f\uff0c\u901a\u5e38\u662f HTML \u9875\u9762\u3002\u54cd\u5e94\u4e2d\u8fd8\u53ef\u80fd\u5305\u542b\u54cd\u5e94\u5934\u3001cookies \u7b49\u4fe1\u606f\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.3 <strong>\u89e3\u6790\u6570\u636e<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u6790\u7f51\u9875\u5185\u5bb9\u662f\u722c\u866b\u7684\u6838\u5fc3\u90e8\u5206\u3002Python \u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u5e93\u6765\u63d0\u53d6\u548c\u5904\u7406\u7f51\u9875\u6570\u636e\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.4 <strong>\u6570\u636e\u5b58\u50a8<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u722c\u53d6\u5230\u7684\u6570\u636e\u901a\u5e38\u4f1a\u88ab\u5b58\u50a8\u5230\u6587\u4ef6\uff08\u5982 CSV\u3001JSON\u3001XML\uff09\uff0c\u6216\u6570\u636e\u5e93\uff08\u5982 SQLite\u3001MySQL\u3001MongoDB\uff09\u4e2d\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u4f7f\u7528\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.5 <strong>\u5904\u7406\u53cd\u722c\u673a\u5236<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f51\u7ad9\u4e3a\u4e86\u9632\u6b62\u722c\u866b\u6293\u53d6\u6570\u636e\uff0c\u901a\u5e38\u4f1a\u91c7\u53d6\u4e00\u4e9b\u53cd\u722c\u63aa\u65bd\uff0c\u5982 IP \u9650\u5236\u3001\u8bf7\u6c42\u9891\u7387\u9650\u5236\u3001\u9a8c\u8bc1\u7801\u7b49\u3002\u5e94\u5bf9\u8fd9\u4e9b\u53cd\u722c\u63aa\u65bd\u662f\u722c\u866b\u5f00\u53d1\u4e2d\u7684\u4e00\u5927\u6311\u6218\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u5e38\u7528\u7684 Python \u722c\u866b\u5e93<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u642d\u5efa\u722c\u866b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684 Python \u722c\u866b\u5e93\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.1 <strong>requests<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>requests<\/code> \u662f Python \u4e2d\u6700\u5e38\u7528\u7684 HTTP \u8bf7\u6c42\u5e93\uff0c\u5b83\u5c01\u88c5\u4e86\u5e95\u5c42\u7684 HTTP \u8bf7\u6c42\uff0c\u7b80\u5316\u4e86\u53d1\u9001\u8bf7\u6c42\u548c\u5904\u7406\u54cd\u5e94\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  pip install requests<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  import requests\n\n  url = 'http:\/\/example.com'\n  response = requests.get(url)\n  print(response.text)  # \u8f93\u51fa\u7f51\u9875 HTML \u5185\u5bb9<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.2 <strong>BeautifulSoup<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>BeautifulSoup<\/code> \u662f\u7528\u4e8e\u89e3\u6790 HTML \u548c XML \u6587\u6863\u7684\u5e93\uff0c\u5b83\u80fd\u591f\u5feb\u901f\u3001\u65b9\u4fbf\u5730\u63d0\u53d6\u7f51\u9875\u4e2d\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  pip install beautifulsoup4<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from bs4 import BeautifulSoup\n  import requests\n\n  url = 'http:\/\/example.com'\n  response = requests.get(url)\n  soup = BeautifulSoup(response.text, 'html.parser')\n\n  # \u63d0\u53d6\u7f51\u9875\u4e2d\u6240\u6709\u7684\u94fe\u63a5\n  for link in soup.find_all('a'):\n      print(link.get('href'))<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.3 <strong>lxml<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>lxml<\/code> \u662f\u4e00\u4e2a\u9ad8\u6548\u7684 XML \u548c HTML \u89e3\u6790\u5e93\uff0c\u652f\u6301 XPath \u548c XSLT\uff0c\u662f\u89e3\u6790 HTML \u6587\u6863\u975e\u5e38\u5feb\u901f\u4e14\u5f3a\u5927\u7684\u5e93\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  pip install lxml<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from lxml import etree\n  import requests\n\n  url = 'http:\/\/example.com'\n  response = requests.get(url)\n  tree = etree.HTML(response.text)\n\n  # \u4f7f\u7528 XPath \u63d0\u53d6\u6570\u636e\n  titles = tree.xpath('\/\/h2\/text()')\n  for title in titles:\n      print(title)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.4 <strong>Selenium<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Selenium<\/code> \u662f\u4e00\u4e2a\u7528\u4e8e\u81ea\u52a8\u5316\u6d4f\u89c8\u5668\u64cd\u4f5c\u7684\u5de5\u5177\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u52a8\u6001\u7f51\u9875\u6293\u53d6\u3002\u5b83\u53ef\u4ee5\u6a21\u62df\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u884c\u4e3a\uff0c\u9002\u7528\u4e8e\u5904\u7406 JavaScript \u6e32\u67d3\u7684\u7f51\u9875\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  pip install selenium<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from selenium import webdriver\n\n  # \u4f7f\u7528 Chrome \u6d4f\u89c8\u5668\u9a71\u52a8\n  driver = webdriver.Chrome(executable_path='\/path\/to\/chromedriver')\n  driver.get('http:\/\/example.com')\n\n  # \u83b7\u53d6\u7f51\u9875\u5185\u5bb9\n  html = driver.page_source\n  print(html)\n\n  driver.quit()<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.5 <strong>Scrapy<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Scrapy<\/code> \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u722c\u866b\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u722c\u866b\u5f00\u53d1\u3002\u5b83\u5185\u5efa\u4e86\u591a\u79cd\u529f\u80fd\uff0c\u5982\u5f02\u6b65\u8bf7\u6c42\u3001\u8bf7\u6c42\u53bb\u91cd\u3001\u81ea\u52a8\u5904\u7406\u91cd\u8bd5\u7b49\uff0c\u9002\u7528\u4e8e\u9ad8\u6548\u722c\u53d6\u5927\u91cf\u6570\u636e\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  pip install scrapy<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  scrapy startproject myproject\n  cd myproject\n  scrapy genspider example example.com\n  scrapy crawl example<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u722c\u53d6\u65b0\u95fb\u7f51\u7ad9<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">3.1 <strong>\u76ee\u6807<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5c06\u4f7f\u7528 <code>requests<\/code> \u548c <code>BeautifulSoup<\/code> \u722c\u53d6\u67d0\u65b0\u95fb\u7f51\u7ad9\u7684\u6807\u9898\u548c\u94fe\u63a5\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.2 <strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u53d1\u9001\u8bf7\u6c42\uff0c\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>BeautifulSoup<\/code> \u89e3\u6790\u7f51\u9875\u3002<\/li>\n\n\n\n<li>\u63d0\u53d6\u6807\u9898\u548c\u94fe\u63a5\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>\u5b58\u50a8\u6570\u636e\uff08\u8fd9\u91cc\u6211\u4eec\u5b58\u50a8\u4e3a CSV \u6587\u4ef6\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">3.3 <strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests\nfrom bs4 import BeautifulSoup\nimport csv\n\n# \u722c\u53d6\u76ee\u6807\u7f51\u7ad9 URL\nurl = 'https:\/\/news.ycombinator.com\/'\n\n# \u53d1\u9001 GET \u8bf7\u6c42\nresponse = requests.get(url)\nresponse.encoding = 'utf-8'\n\n# \u89e3\u6790\u7f51\u9875\u5185\u5bb9\nsoup = BeautifulSoup(response.text, 'html.parser')\n\n# \u6253\u5f00 CSV \u6587\u4ef6\u7528\u4e8e\u5b58\u50a8\u6570\u636e\nwith open('news_titles.csv', 'w', newline='', encoding='utf-8') as file:\n    writer = csv.writer(file)\n    writer.writerow(&#91;'Title', 'Link'])\n\n    # \u63d0\u53d6\u6240\u6709\u65b0\u95fb\u6807\u9898\u548c\u94fe\u63a5\n    for item in soup.find_all('a', class_='storylink'):\n        title = item.get_text()\n        link = item.get('href')\n        writer.writerow(&#91;title, link])\n\nprint('\u6570\u636e\u5df2\u4fdd\u5b58\u5230 news_titles.csv \u6587\u4ef6\u4e2d')<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3.4 <strong>\u4ee3\u7801\u89e3\u6790<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53d1\u9001\u8bf7\u6c42\u83b7\u53d6\u7f51\u9875 HTML \u5185\u5bb9\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>BeautifulSoup<\/code> \u89e3\u6790 HTML\uff0c\u67e5\u627e\u6240\u6709\u65b0\u95fb\u6807\u9898\uff08<code>&lt;a><\/code> \u6807\u7b7e\uff0c<code>class=\"storylink\"<\/code>\uff09\u3002<\/li>\n\n\n\n<li>\u63d0\u53d6\u6807\u9898\u6587\u672c\u548c\u94fe\u63a5\uff0c\u5e76\u4fdd\u5b58\u5230 CSV \u6587\u4ef6\u4e2d\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u53cd\u722c\u63aa\u65bd\u4e0e\u5e94\u5bf9<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bb8\u591a\u7f51\u7ad9\u4f1a\u5bf9\u722c\u866b\u91c7\u53d6\u53cd\u722c\u63aa\u65bd\uff0c\u5e38\u89c1\u7684\u53cd\u722c\u7b56\u7565\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>IP \u9650\u5236<\/strong>\uff1a\u7f51\u7ad9\u5bf9\u540c\u4e00 IP \u5730\u5740\u53d1\u51fa\u7684\u8bf7\u6c42\u9891\u7387\u8fdb\u884c\u9650\u5236\u3002<\/li>\n\n\n\n<li><strong>User-Agent \u9650\u5236<\/strong>\uff1a\u901a\u8fc7\u68c0\u6d4b\u8bf7\u6c42\u5934\u4e2d\u7684 <code>User-Agent<\/code> \u6765\u5224\u65ad\u662f\u5426\u662f\u722c\u866b\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1\u7801<\/strong>\uff1a\u901a\u8fc7\u663e\u793a\u9a8c\u8bc1\u7801\u6765\u963b\u6b62\u81ea\u52a8\u5316\u811a\u672c\u3002<\/li>\n\n\n\n<li><strong>JavaScript \u6e32\u67d3<\/strong>\uff1a\u67d0\u4e9b\u7f51\u7ad9\u4f7f\u7528 JavaScript \u52a8\u6001\u52a0\u8f7d\u5185\u5bb9\uff0c\u65e0\u6cd5\u901a\u8fc7\u666e\u901a\u7684 HTTP \u8bf7\u6c42\u83b7\u53d6\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.1 <strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u4ee3\u7406 IP<\/strong>\uff1a\u901a\u8fc7\u5207\u6362\u4ee3\u7406 IP \u5730\u5740\uff0c\u7ed5\u8fc7 IP \u9650\u5236\u3002<\/li>\n\n\n\n<li><strong>\u8bbe\u7f6e User-Agent<\/strong>\uff1a\u4f2a\u88c5\u6210\u6d4f\u89c8\u5668\u8bf7\u6c42\uff0c\u907f\u514d\u88ab\u8bc6\u522b\u4e3a\u722c\u866b\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  headers = {\n      'User-Agent': 'Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/91.0.4472.124 Safari\/537.36'\n  }\n  response = requests.get(url, headers=headers)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 Selenium<\/strong>\uff1a\u9488\u5bf9 JavaScript \u6e32\u67d3\u7684\u7f51\u9875\uff0c\u53ef\u4ee5\u4f7f\u7528 Selenium \u6a21\u62df\u6d4f\u89c8\u5668\u8fdb\u884c\u52a8\u6001\u52a0\u8f7d\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.2 <strong>\u9a8c\u8bc1\u7801\u7ed5\u8fc7<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u9a8c\u8bc1\u7801\uff0c\u4e00\u4e9b\u7f51\u7ad9\u91c7\u7528\u4e86\u56fe\u50cf\u9a8c\u8bc1\u7801\uff08\u5982 reCAPTCHA\uff09\u3002\u7ed5\u8fc7\u9a8c\u8bc1\u7801\u7684\u505a\u6cd5\u6709\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u624b\u52a8\u8f93\u5165<\/strong>\uff1a\u6700\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u4f46\u4e0d\u9002\u5408\u5927\u89c4\u6a21\u722c\u866b\u3002<\/li>\n\n\n\n<li><strong>\u96c6\u6210 OCR<\/strong>\uff1a\u901a\u8fc7 Optical Character Recognition\uff08OCR\uff09\u6280\u672f\u8bc6\u522b\u56fe\u50cf\u4e2d\u7684\u9a8c\u8bc1\u7801\uff08\u5982\u4f7f\u7528 <code>tesseract<\/code> \u5e93\uff09\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u670d\u52a1<\/strong>\uff1a\u4f8b\u5982 <code>2Captcha<\/code> \u7b49 API\uff0c\u8fdb\u884c\u9a8c\u8bc1\u7801\u81ea\u52a8\u7834\u89e3\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u6570\u636e\u5b58\u50a8\u4e0e\u5206\u6790<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u722c\u866b\u91c7\u96c6\u7684\u6570\u636e\u901a\u5e38\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\uff0c\u5e38\u89c1\u7684\u683c\u5f0f\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CSV \u6587\u4ef6<\/strong>\uff1a\u9002\u7528\u4e8e\u8868\u683c\u6570\u636e\u5b58\u50a8\u3002<\/li>\n\n\n\n<li><strong>JSON \u6587\u4ef6<\/strong>\uff1a\u9002\u7528\u4e8e\u5b58\u50a8\u7ed3\u6784\u5316\u6570\u636e\uff0c\u7279\u522b\u662f\u5d4c\u5957\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u5e93<\/strong>\uff1a\u5982 SQLite\u3001MySQL\u3001MongoDB\uff0c\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u5b58\u50a8\u4e0e\u9ad8\u6548\u67e5\u8be2\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">5.1 <strong>\u5b58\u50a8\u4e3a JSON<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\ndata = {\n    'title': 'Example Title',\n    'link': 'http:\/\/example.com'\n}\n\n# \u4fdd\u5b58\u4e3a JSON \u6587\u4ef6\nwith open('data.json', 'w') as f:\n    json.dump(data, f)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5.2 <strong>\u5b58\u50a8\u4e3a SQLite<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import sqlite3\n\n# \u8fde\u63a5 SQLite \u6570\u636e\u5e93\uff08\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u4f1a\u81ea\u52a8\u521b\u5efa\uff09\nconn = sqlite3.connect('data.db')\ncursor = conn.cursor()\n\n# \u521b\u5efa\u8868\ncursor.execute('CREATE TABLE IF NOT EXISTS news (title TEXT, link TEXT)')\n\n# \u63d2\u5165\u6570\u636e\ncursor.execute('INSERT INTO news (title, link) VALUES (?, ?)', ('Example Title', 'http:\/\/example.com'))\n\n# \u63d0\u4ea4\u5e76\n\n\u5173\u95ed\u8fde\u63a5\nconn.commit()\nconn.close()<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u722c\u866b\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u6293\u53d6\u7f51\u9875\u5185\u5bb9\u5e76\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002\u901a\u8fc7\u719f\u6089\u5e38\u7528\u7684\u722c\u866b\u5e93\uff08\u5982 <code>requests<\/code>\u3001<code>BeautifulSoup<\/code>\u3001<code>Scrapy<\/code> \u7b49\uff09\uff0c\u5e76\u5408\u7406\u5e94\u5bf9\u53cd\u722c\u673a\u5236\uff0c\u53ef\u4ee5\u6784\u5efa\u9ad8\u6548\u7684\u722c\u866b\u7a0b\u5e8f\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u5904\u7406\u53cd\u722c\u95ee\u9898\u662f\u6210\u529f\u722c\u53d6\u6570\u636e\u7684\u5173\u952e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u722c\u866b\u662f\u5229\u7528\u7a0b\u5e8f\u6a21\u62df\u6d4f\u89c8\u5668\u7684\u884c\u4e3a\uff0c\u901a\u8fc7\u53d1\u9001 HTTP \u8bf7\u6c42\u83b7\u53d6\u7f51\u9875\u5185\u5bb9\u5e76\u89e3\u6790\u3001\u63d0\u53d6\u4fe1\u606f\u7684\u8fc7\u7a0b\u3002\u722c\u866b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":2,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"predecessor-version":[{"id":895,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/767\/revisions\/895"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}