<thead id="xxgg8"></thead>
\n    

橡皮擦的爬蟲(chóng)課<\/h2>\n    

用一段自定義的 HTML 代碼來(lái)演示<\/p>\n  <\/body>\n<\/html><\/pre>

使用 BeautifulSoup<\/code> 對(duì)其進(jìn)行簡(jiǎn)單的操作,包含實(shí)例化 BS 對(duì)象,輸出頁(yè)面標(biāo)簽等內(nèi)容。<\/p>

from bs4 import BeautifulSoup\ntext_str = \"\"\"\n\t\n\t\t測(cè)試bs4模塊腳本<\/title>\n\t<\/head>\n\t<body>
<h1><a href="http://www.miracleart.cn/">国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂</a></h1>\n\t\t<h2>橡皮擦的爬蟲(chóng)課<\/h2>\n\t\t<p>用1段自定義的 HTML 代碼來(lái)演示<\/p>\n\t\t<p>用2段自定義的 HTML 代碼來(lái)演示<\/p>\n\t<\/body>\n<\/html>\n\"\"\"\n# 實(shí)例化 Beautiful Soup 對(duì)象\nsoup = BeautifulSoup(text_str, \"html.parser\")\n# 上述是將字符串格式化為 Beautiful Soup 對(duì)象,你可以從一個(gè)文件進(jìn)行格式化\n# soup = BeautifulSoup(open('test.html'))\nprint(soup)\n# 輸入網(wǎng)頁(yè)標(biāo)題 title 標(biāo)簽\nprint(soup.title)\n# 輸入網(wǎng)頁(yè) head 標(biāo)簽\nprint(soup.head)\n\n# 測(cè)試輸入段落標(biāo)簽 p\nprint(soup.p) # 默認(rèn)獲取第一個(gè)<\/pre><p>我們可以通過(guò) BeautifulSoup 對(duì)象,直接調(diào)用網(wǎng)頁(yè)標(biāo)簽,這里存在一個(gè)問(wèn)題,通過(guò) BS 對(duì)象調(diào)用標(biāo)簽只能獲取排在第一位置上的標(biāo)簽,如上述代碼中,只獲取到了一個(gè) <code>p<\/code> 標(biāo)簽,如果想要獲取更多內(nèi)容,請(qǐng)繼續(xù)閱讀。<\/p><p><strong>學(xué)習(xí)到這里,我們需要了解 BeautifulSoup 中的 4 個(gè)內(nèi)置對(duì)象:<\/strong><\/p><ul class=\" list-paddingleft-2\"><li><p><code>BeautifulSoup<\/code>:基本對(duì)象,整個(gè) HTML 對(duì)象,一般當(dāng)做 Tag 對(duì)象看即可;<\/p><\/li><li><p><code>Tag<\/code>:標(biāo)簽對(duì)象,標(biāo)簽就是網(wǎng)頁(yè)中的各個(gè)節(jié)點(diǎn),例如 title,head,p;<\/p><\/li><li><p><code>NavigableString<\/code>:標(biāo)簽內(nèi)部字符串;<\/p><\/li><li><p><code>Comment<\/code>:注釋對(duì)象,爬蟲(chóng)里面使用場(chǎng)景不多。<\/p><\/li><\/ul><p><strong>下述代碼為你演示這幾種對(duì)象出現(xiàn)的場(chǎng)景,注意代碼中的相關(guān)注釋?zhuān)?\/strong><\/p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup\ntext_str = \"\"\"<html>\n\t<head>\n\t\t<title>測(cè)試bs4模塊腳本<\/title>\n\t<\/head>\n\t<body>\n\t\t<h2>橡皮擦的爬蟲(chóng)課<\/h2>\n\t\t<p>用1段自定義的 HTML 代碼來(lái)演示<\/p>\n\t\t<p>用2段自定義的 HTML 代碼來(lái)演示<\/p>\n\t<\/body>\n<\/html>\n\"\"\"\n# 實(shí)例化 Beautiful Soup 對(duì)象\nsoup = BeautifulSoup(text_str, \"html.parser\")\n# 上述是將字符串格式化為 Beautiful Soup 對(duì)象,你可以從一個(gè)文件進(jìn)行格式化\n# soup = BeautifulSoup(open('test.html'))\nprint(soup)\nprint(type(soup))  # <class 'bs4.BeautifulSoup'>\n# 輸入網(wǎng)頁(yè)標(biāo)題 title 標(biāo)簽\nprint(soup.title)\nprint(type(soup.title)) # <class 'bs4.element.Tag'>\nprint(type(soup.title.string)) # <class 'bs4.element.NavigableString'>\n# 輸入網(wǎng)頁(yè) head 標(biāo)簽\nprint(soup.head)<\/pre><p><strong>對(duì)于 <strong>Tag 對(duì)象<\/strong>,有兩個(gè)重要的屬性,是 <code>name<\/code> 和 <code>attrs<\/code><\/strong><\/p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup\ntext_str = \"\"\"<html>\n\t<head>\n\t\t<title>測(cè)試bs4模塊腳本<\/title>\n\t<\/head>\n\t<body>\n\t\t<h2>橡皮擦的爬蟲(chóng)課<\/h2>\n\t\t<p>用1段自定義的 HTML 代碼來(lái)演示<\/p>\n\t\t<p>用2段自定義的 HTML 代碼來(lái)演示<\/p>\n\t\t<a href=\"http:\/\/www.csdn.net\" rel=\"external nofollow\"  rel=\"external nofollow\" >CSDN 網(wǎng)站<\/a>\n\t<\/body>\n<\/html>\n\"\"\"\n# 實(shí)例化 Beautiful Soup 對(duì)象\nsoup = BeautifulSoup(text_str, \"html.parser\")\nprint(soup.name) # [document]\nprint(soup.title.name) # 獲取標(biāo)簽名 title\nprint(soup.html.body.a) # 可以通過(guò)標(biāo)簽層級(jí)獲取下層標(biāo)簽\nprint(soup.body.a) # html 作為一個(gè)特殊的根標(biāo)簽,可以省略\nprint(soup.p.a) # 無(wú)法獲取到 a 標(biāo)簽\nprint(soup.a.attrs) # 獲取屬性<\/pre><p>上述代碼演示了獲取 <code>name<\/code> 屬性和 <code>attrs<\/code> 屬性的用法,其中 <code>attrs<\/code> 屬性得到的是一個(gè)字典,可以通過(guò)鍵獲取對(duì)應(yīng)的值。<\/p><p>獲取標(biāo)簽的屬性值,在 BeautifulSoup 中,還可以使用如下方法:<\/p><pre class='brush:php;toolbar:false;'>print(soup.a[\"href\"])\nprint(soup.a.get(\"href\"))<\/pre><p><strong>獲取 <code>NavigableString<\/code> 對(duì)象<\/strong> 獲取了網(wǎng)頁(yè)標(biāo)簽之后,就要獲取標(biāo)簽內(nèi)文本了,通過(guò)下述代碼進(jìn)行。<\/p><pre class='brush:php;toolbar:false;'>print(soup.a.string)<\/pre><p>除此之外,你還可以使用 <code>text<\/code> 屬性和 <code>get_text()<\/code> 方法獲取標(biāo)簽內(nèi)容。<\/p><pre class='brush:php;toolbar:false;'>print(soup.a.string)\nprint(soup.a.text)\nprint(soup.a.get_text())<\/pre><p>還可以獲取標(biāo)簽內(nèi)所有文本,使用 <code>strings<\/code> 和 <code>stripped_strings<\/code> 即可。<\/p><pre class='brush:php;toolbar:false;'>print(list(soup.body.strings)) # 獲取到空格或者換行\(zhòng)nprint(list(soup.body.stripped_strings)) # 去除空格或者換行<\/pre><p><strong>擴(kuò)展標(biāo)簽\/節(jié)點(diǎn)選擇器之遍歷文檔樹(shù)<\/strong><\/p><p>直接子節(jié)點(diǎn)<\/p><p>標(biāo)簽(Tag)對(duì)象的直接子元素,可以使用 <code>contents<\/code> 和 <code>children<\/code> 屬性獲取。<\/p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup\ntext_str = \"\"\"<html>\n\t<head>\n\t\t<title>測(cè)試bs4模塊腳本<\/title>\n\t<\/head>\n\t<body>\n\t\t<div id=\"content\">\n\t\t\t<h2>橡皮擦的爬蟲(chóng)課<span>最棒<\/span><\/h2>\n            <p>用1段自定義的 HTML 代碼來(lái)演示<\/p>\n            <p>用2段自定義的 HTML 代碼來(lái)演示<\/p>\n            <a href=\"http:\/\/www.csdn.net\" rel=\"external nofollow\"  rel=\"external nofollow\" >CSDN 網(wǎng)站<\/a>\n\t\t<\/div>\n        <ul class=\"nav\">\n            <li>首頁(yè)<\/li>\n            <li>博客<\/li>\n            <li>專(zhuān)欄課程<\/li>\n        <\/ul>\n\n\t<\/body>\n<\/html>\n\"\"\"\n# 實(shí)例化 Beautiful Soup 對(duì)象\nsoup = BeautifulSoup(text_str, \"html.parser\")\n# contents 屬性獲取節(jié)點(diǎn)的直接子節(jié)點(diǎn),以列表的形式返回內(nèi)容\nprint(soup.div.contents) # 返回列表\n# children 屬性獲取的也是節(jié)點(diǎn)的直接子節(jié)點(diǎn),以生成器的類(lèi)型返回\nprint(soup.div.children) # 返回 <list_iterator object at 0x00000111EE9B6340><\/pre><p>請(qǐng)注意以上兩個(gè)屬性獲取的都是<strong>直接<\/strong>子節(jié)點(diǎn),例如 <code>h2<\/code> 標(biāo)簽內(nèi)的后代標(biāo)簽 <code>span<\/code> ,不會(huì)單獨(dú)獲取到。<\/p><p>如果希望將所有的標(biāo)簽都獲取到,使用 <code>descendants<\/code> 屬性,它返回的是一個(gè)生成器,所有標(biāo)簽包括標(biāo)簽內(nèi)的文本都會(huì)單獨(dú)獲取。<\/p><pre class='brush:php;toolbar:false;'>print(list(soup.div.descendants))<\/pre><p>其它節(jié)點(diǎn)的獲取(了解即可,即查即用)<\/p><ul class=\" list-paddingleft-2\"><li><p><code>parent<\/code> 和 <code>parents<\/code>:直接父節(jié)點(diǎn)和所有父節(jié)點(diǎn);<\/p><\/li><li><p><code>next_sibling<\/code>,<code>next_siblings<\/code>,<code>previous_sibling<\/code>,<code>previous_siblings<\/code>:分別表示下一個(gè)兄弟節(jié)點(diǎn)、下面所有兄弟節(jié)點(diǎn)、上一個(gè)兄弟節(jié)點(diǎn)、上面所有兄弟節(jié)點(diǎn),由于換行符也是一個(gè)節(jié)點(diǎn),所有在使用這幾個(gè)屬性時(shí),要注意一下?lián)Q行符;<\/p><\/li><li><p><code>next_element<\/code>,<code>next_elements<\/code>,<code>previous_element<\/code>,<code>previous_elements<\/code>:這幾個(gè)屬性分別表示上一個(gè)節(jié)點(diǎn)或者下一個(gè)節(jié)點(diǎn),注意它們不分層次,而是針對(duì)所有節(jié)點(diǎn),例如上述代碼中 <code>div<\/code> 節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)是 <code>h2<\/code>,而 <code>div<\/code> 節(jié)點(diǎn)的兄弟節(jié)點(diǎn)是 <code>ul<\/code>。<\/p><\/li><\/ul><p><strong>文檔樹(shù)搜索相關(guān)函數(shù)<\/strong><\/p><p>第一個(gè)要學(xué)習(xí)的函數(shù)就是 <code>find_all()<\/code> 函數(shù),<strong>原型如下所示:<\/strong><\/p><pre class='brush:php;toolbar:false;'>find_all(name,attrs,recursive,text,limit=None,**kwargs)<\/pre><ul class=\" list-paddingleft-2\"><li><p><code>name<\/code>:該參數(shù)為 tag 標(biāo)簽的名字,例如 <code>find_all('p')<\/code> 是查找所有的 <code>p<\/code><\/p><strong>La commande d'installation de la bibliothèque est la suivante?:<\/strong>#????#<pre class='brush:php;toolbar:false;'>print(soup.find_all('li')) # 獲取所有的 li\nprint(soup.find_all(attrs={'class': 'nav'})) # 傳入 attrs 屬性\nprint(soup.find_all(re.compile(\"p\"))) # 傳遞正則,實(shí)測(cè)效果不理想\nprint(soup.find_all(['a','p'])) # 傳遞列表<\/pre>#????#<code>BeautifulSoup<\/code> Lors de l'analyse des données, vous devez s'appuyer sur des analyseurs tiers,<strong>les analyseurs couramment utilisés et leurs avantages sont les suivants?:<\/strong>#????#<ul class=\" list-paddingleft-2\"><li>#????#<code> analyseur standard python html.<\/code>?: bibliothèque standard intégrée python, forte tolérance aux pannes?; #????#<\/li><li>#????#<code>analyseur lxml<\/code>?: rapide, puissant?; tolérance aux pannes?; #?? ??#<\/li><li>#????#<code>html5lib<\/code>?: la plus tolérante aux pannes et la méthode d'analyse est cohérente avec le navigateur. #????#<\/li><\/ul>#????# Ensuite, utilisez un code HTML personnalisé pour démontrer l'utilisation de base de la bibliothèque <code>beautifulsoup4<\/code> Le code de test est le suivant?: #????. #<pre class='brush:php;toolbar:false;'>print(soup.body.div.find_all(['a','p'],recursive=False)) # 傳遞列表<\/pre># ????#Utilisez <code>BeautifulSoup<\/code> pour effectuer des opérations simples dessus, notamment l'instanciation d'objets BS, la sortie de balises de page, etc. #????#<pre class='brush:php;toolbar:false;'>print(soup.find_all(text='首頁(yè)')) # ['首頁(yè)']\nprint(soup.find_all(text=re.compile(\"^首\"))) # ['首頁(yè)']\nprint(soup.find_all(text=[\"首頁(yè)\",re.compile('課')])) # ['橡皮擦的爬蟲(chóng)課', '首頁(yè)', '專(zhuān)欄課程']<\/pre>#????#Nous pouvons appeler directement la balise de page Web via l'objet BeautifulSoup. Il y a un problème ici. L'appel de la balise via l'objet BS ne peut que classer la balise en premier. la balise en première position est obtenue. Une balise <code>p<\/code>, si vous souhaitez obtenir plus de contenu, veuillez continuer à lire. #????##????#<strong>Après avoir appris cela, nous devons comprendre les 4 objets intégrés dans BeautifulSoup?:<\/strong>#????#<ul class=\" list-paddingleft-2\"><li ># ????#<code>BeautifulSoup<\/code>?: Objet de base, l'objet HTML entier, généralement considéré comme un objet Tag?; #????#<\/li><li>#????#<code>Tag<\/?; code> : Objet Label, l'étiquette est chaque n?ud de la page Web, tel que title, head, p; #????#<\/li><li>#????#<code>NavigableString<\/code>?: Label internal string; #?? ??#<\/li><li>#????#<code>Comment<\/code>?: Objet de commentaire, il n'y a pas beaucoup de scénarios d'utilisation dans les robots. #????#<\/li><\/ul>#????#<strong>Le code suivant vous montre les scénarios dans lesquels ces objets apparaissent. Faites attention aux commentaires pertinents dans le code?: <\/strong>#????#. <pre class='brush:php;toolbar:false;'>print(soup.find_all(class_ = 'nav'))\nprint(soup.find_all(class_ = 'nav li'))<\/pre># ????#<strong>Pour l'<strong>objet Tag<\/strong>, il existe deux attributs importants, qui sont <code>name<\/code> et <code>attrs<\/code><\/strong>#?? ??# <pre class='brush:php;toolbar:false;'>print(soup.select('ul[class^=\"na\"]'))<\/pre>#????#Le code ci-dessus démontre l'utilisation de l'obtention de l'attribut <code>name<\/code> et de l'attribut <code>attrs<\/code>. L'attribut <code>attrs<\/code> obtient un dictionnaire. , qui peut être transmis Key obtient la valeur correspondante. #????##????#Obtenir la valeur d'attribut de la balise Dans BeautifulSoup, vous pouvez également utiliser la méthode suivante : #????#<pre class='brush:php;toolbar:false;'>print(soup.select('ul[class*=\"li\"]'))<\/pre>#????#<strong>Obtenir l'objet <code>NavigableString<\/code>< \/strong> Après avoir obtenu la balise de page Web, vous devez obtenir le texte contenu dans la balise, ce qui se fait via le code suivant. #????#<pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup\nimport requests\nimport logging\nlogging.basicConfig(level=logging.NOTSET)\ndef get_html(url, headers) -> None:\n    try:\n        res = requests.get(url=url, headers=headers, timeout=3)\n    except Exception as e:\n        logging.debug(\"采集異常\", e)\n\n    if res is not None:\n        html_str = res.text\n        soup = BeautifulSoup(html_str, \"html.parser\")\n        imgs = soup.find_all(attrs={'class': 'lazy'})\n        print(\"獲取到的數(shù)據(jù)量是\", len(imgs))\n        datas = []\n        for item in imgs:\n            name = item.get('alt')\n            src = item[\"src\"]\n            logging.info(f\"{name},{src}\")\n            # 獲取拼接數(shù)據(jù)\n            datas.append((name, src))\n        save(datas, headers)\ndef save(datas, headers) -> None:\n    if datas is not None:\n        for item in datas:\n            try:\n                # 抓取圖片\n                res = requests.get(url=item[1], headers=headers, timeout=5)\n            except Exception as e:\n                logging.debug(e)\n\n            if res is not None:\n                img_data = res.content\n                with open(\".\/imgs\/{}.jpg\".format(item[0]), \"wb+\") as f:\n                    f.write(img_data)\n    else:\n        return None\nif __name__ == '__main__':\n    headers = {\n        \"User-Agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/93.0.4577.82 Safari\/537.36\"\n    }\n    url_format = \"http:\/\/www.9thws.com\/#p{}\"\n    urls = [url_format.format(i) for i in range(1, 2)]\n    get_html(urls[0], headers)<\/pre>#????#De plus, vous pouvez également utiliser l'attribut <code>text<\/code> et la méthode <code>get_text()<\/code> pour obtenir le contenu de la balise. #????#rrreee#????# Vous pouvez également obtenir tout le texte de la balise en utilisant <code>strings<\/code> et <code>stripped_strings<\/code>. #????#rrreee#????#<strong>Sélecteur de balise\/n?ud étendu traversant l'arborescence du document<\/strong>#????##????#N?ud enfant direct#????##????#Objet Tag Les éléments enfants directs peut être obtenu en utilisant les attributs <code>contents<\/code> et <code>children<\/code>. #????#rrreee#????#Veuillez noter que les deux attributs ci-dessus obtiennent les n?uds enfants <strong>directs<\/strong>, tels que la balise descendante <code>span<\/ dans le <code>h2<\/code> code de balise> ne sera pas obtenu séparément. #????##????#Si vous souhaitez obtenir toutes les balises, utilisez l'attribut <code>descendants<\/code>. Il renvoie un générateur et toutes les balises, y compris le texte à l'intérieur des balises, seront récupérées séparément. #????#rrreee#????#Acquisition d'autres n?uds (il suffit de comprendre, vérifier et utiliser) #????#<ul class=\"list-paddingleft-2\"><li>#????#<code>parent <\/ code> et <code>parents<\/code>?: n?ud parent direct et tous les n?uds parents?; #????#<\/li><li>#????#<code>next_sibling<\/code>, <code>next_siblings <\/ code>, <code>previous_sibling<\/code>, <code>previous_siblings<\/code>?: représentent respectivement le n?ud frère suivant, tous les n?uds frères en dessous, le n?ud frère précédent et tous les n?uds frères au-dessus puisque le caractère de nouvelle ligne est également. un n?ud, lorsque vous utilisez ces attributs, veuillez faire attention au saut de ligne #????#<\/li><li>#????#<code>next_element<\/code>, <code>next_elements<\/code>, < code>previous_element<\/code>, <code>previous_elements<\/code>?: ces attributs représentent respectivement le n?ud précédent ou le n?ud suivant. Notez qu'ils ne sont pas hiérarchiques, mais ciblent tous les n?uds, comme dans le code ci-dessus <code The. Le n?ud suivant du n?ud >div<\/code> est <code>h2<\/code>, et le n?ud frère du n?ud <code>div<\/code> est <code>ul<\/code>. #????#<\/li><\/ul>#????#<strong>Fonctions liées à la recherche dans l'arborescence des documents<\/strong>#????##????#La première fonction à apprendre est <code>find_all() <\/ code>, <strong>le prototype est le suivant : <\/strong>#????#rrreee<ul class=\" list-paddingleft-2\"><li>#????#<code>name<\/code> : Ce paramètre est le nom de la balise. Par exemple, <code>find_all('p')<\/code> sert à rechercher toutes les balises <code>p<\/code>. Il peut accepter les cha?nes de nom de balise, les expressions régulières et. listes #????#<\/li><li><p><code>attrs<\/code>:傳入的屬性,該參數(shù)可以字典的形式傳入,例如 <code>attrs={'class': 'nav'}<\/code>,返回的結(jié)果是 tag 類(lèi)型的列表;<\/p><\/li><\/ul><p><strong>上述兩個(gè)參數(shù)的用法示例如下:<\/strong><\/p><pre class='brush:php;toolbar:false;'>print(soup.find_all('li')) # 獲取所有的 li\nprint(soup.find_all(attrs={'class': 'nav'})) # 傳入 attrs 屬性\nprint(soup.find_all(re.compile(\"p\"))) # 傳遞正則,實(shí)測(cè)效果不理想\nprint(soup.find_all(['a','p'])) # 傳遞列表<\/pre><ul class=\" list-paddingleft-2\"><li><p><code>recursive<\/code>:調(diào)用 <code>find_all ()<\/code> 方法時(shí),BeautifulSoup 會(huì)檢索當(dāng)前 tag 的所有子孫節(jié)點(diǎn),如果只想搜索 tag 的直接子節(jié)點(diǎn),可以使用參數(shù) <code>recursive=False<\/code>,測(cè)試代碼如下:<\/p><\/li><\/ul><pre class='brush:php;toolbar:false;'>print(soup.body.div.find_all(['a','p'],recursive=False)) # 傳遞列表<\/pre><ul class=\" list-paddingleft-2\"><li><p><code>text<\/code>:可以檢索文檔中的文本字符串內(nèi)容,與 <code>name<\/code> 參數(shù)的可選值一樣,<code>text<\/code> 參數(shù)接受標(biāo)簽名字符串、正則表達(dá)式、 列表;<\/p><\/li><\/ul><pre class='brush:php;toolbar:false;'>print(soup.find_all(text='首頁(yè)')) # ['首頁(yè)']\nprint(soup.find_all(text=re.compile(\"^首\"))) # ['首頁(yè)']\nprint(soup.find_all(text=[\"首頁(yè)\",re.compile('課')])) # ['橡皮擦的爬蟲(chóng)課', '首頁(yè)', '專(zhuān)欄課程']<\/pre><ul class=\" list-paddingleft-2\"><li><p><code>limit<\/code>:可以用來(lái)限制返回結(jié)果的數(shù)量;<\/p><\/li><li><p><code>kwargs<\/code>:如果一個(gè)指定名字的參數(shù)不是搜索內(nèi)置的參數(shù)名,搜索時(shí)會(huì)把該參數(shù)當(dāng)作 tag 的屬性來(lái)搜索。這里要按 <code>class<\/code> 屬性搜索,因?yàn)?nbsp;<code>class<\/code> 是 python 的保留字,需要寫(xiě)作 <code>class_<\/code>,按 <code>class_<\/code> 查找時(shí),只要一個(gè) CSS 類(lèi)名滿(mǎn)足即可,如需多個(gè) CSS 名稱(chēng),填寫(xiě)順序需要與標(biāo)簽一致。<\/p><\/li><\/ul><pre class='brush:php;toolbar:false;'>print(soup.find_all(class_ = 'nav'))\nprint(soup.find_all(class_ = 'nav li'))<\/pre><p>還需要注意網(wǎng)頁(yè)節(jié)點(diǎn)中,有些屬性在搜索中不能作為<code>kwargs<\/code>參數(shù)使用,比如<code>html5<\/code> 中的 <code>data-*<\/code>屬性,需要通過(guò)<code>attrs<\/code>參數(shù)進(jìn)行匹配。<\/p><blockquote><p>與 <code>find_all()<\/code>方法用戶(hù)基本一致的其它方法清單如下:<\/p><\/blockquote><ul class=\" list-paddingleft-2\"><li><p><code>find()<\/code>:函數(shù)原型<code>find( name , attrs , recursive , text , **kwargs )<\/code>,返回一個(gè)匹配元素;<\/p><\/li><li><p><code>find_parents(),find_parent()<\/code>:函數(shù)原型 <code>find_parent(self, name=None, attrs={}, **kwargs)<\/code>,返回當(dāng)前節(jié)點(diǎn)的父級(jí)節(jié)點(diǎn);<\/p><\/li><li><p><code>find_next_siblings(),find_next_sibling()<\/code>:函數(shù)原型 <code>find_next_sibling(self, name=None, attrs={}, text=None, **kwargs)<\/code>,返回當(dāng)前節(jié)點(diǎn)的下一兄弟節(jié)點(diǎn);<\/p><\/li><li><p><code>find_previous_siblings(),find_previous_sibling()<\/code>:同上,返回當(dāng)前的節(jié)點(diǎn)的上一兄弟節(jié)點(diǎn);<\/p><\/li><li><p><code>find_all_next(),find_next(),find_all_previous () ,find_previous ()<\/code>:函數(shù)原型 <code>find_all_next(self, name=None, attrs={}, text=None, limit=None, **kwargs)<\/code>,檢索當(dāng)前節(jié)點(diǎn)的后代節(jié)點(diǎn)。<\/p><\/li><\/ul><p><strong>CSS 選擇器<\/strong> 該小節(jié)的知識(shí)點(diǎn)與<code>pyquery<\/code>有點(diǎn)撞車(chē),核心使用<code>select()<\/code>方法即可實(shí)現(xiàn),返回?cái)?shù)據(jù)是列表元組。<\/p><ul class=\" list-paddingleft-2\"><li><p>通過(guò)標(biāo)簽名查找,<code>soup.select(\"title\")<\/code>;<\/p><\/li><li><p>通過(guò)類(lèi)名查找,<code>soup.select(\".nav\")<\/code>;<\/p><\/li><li><p>通過(guò) id 名查找,<code>soup.select(\"#content\")<\/code>;<\/p><\/li><li><p>通過(guò)組合查找,<code>soup.select(\"div#content\")<\/code>;<\/p><\/li><li><p>通過(guò)屬性查找,<code>soup.select(\"div[id='content'\")<\/code>,<code>soup.select(\"a[href]\")<\/code>;<\/p><\/li><\/ul><p>在通過(guò)屬性查找時(shí),還有一些技巧可以使用,<strong>例如:<\/strong><\/p><ul class=\" list-paddingleft-2\"><li><p><code>^=<\/code>:可以獲取以 XX 開(kāi)頭的節(jié)點(diǎn):<\/p><\/li><\/ul><pre class='brush:php;toolbar:false;'>print(soup.select('ul[class^=\"na\"]'))<\/pre><ul class=\" list-paddingleft-2\"><li><p><code>*=<\/code>:獲取屬性包含指定字符的節(jié)點(diǎn):<\/p><\/li><\/ul><pre class='brush:php;toolbar:false;'>print(soup.select('ul[class*=\"li\"]'))<\/pre><h3>二、爬蟲(chóng)案例<\/h3><p>BeautifulSoup 的基礎(chǔ)知識(shí)掌握之后,在進(jìn)行爬蟲(chóng)案例的編寫(xiě),就非常簡(jiǎn)單了,本次要采集的目標(biāo)網(wǎng)站 ,該目標(biāo)網(wǎng)站有大量的藝術(shù)二維碼,可以供設(shè)計(jì)大哥做參考。<\/p><p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/168381546889285.png\" alt=\"Comment utiliser le module python beautifulsoup4\" \/><\/p><p><strong>下述應(yīng)用到了 BeautifulSoup 模塊的標(biāo)簽檢索與屬性檢索,完整代碼如下:<\/strong><\/p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup\nimport requests\nimport logging\nlogging.basicConfig(level=logging.NOTSET)\ndef get_html(url, headers) -> None:\n    try:\n        res = requests.get(url=url, headers=headers, timeout=3)\n    except Exception as e:\n        logging.debug(\"采集異常\", e)\n\n    if res is not None:\n        html_str = res.text\n        soup = BeautifulSoup(html_str, \"html.parser\")\n        imgs = soup.find_all(attrs={'class': 'lazy'})\n        print(\"獲取到的數(shù)據(jù)量是\", len(imgs))\n        datas = []\n        for item in imgs:\n            name = item.get('alt')\n            src = item[\"src\"]\n            logging.info(f\"{name},{src}\")\n            # 獲取拼接數(shù)據(jù)\n            datas.append((name, src))\n        save(datas, headers)\ndef save(datas, headers) -> None:\n    if datas is not None:\n        for item in datas:\n            try:\n                # 抓取圖片\n                res = requests.get(url=item[1], headers=headers, timeout=5)\n            except Exception as e:\n                logging.debug(e)\n\n            if res is not None:\n                img_data = res.content\n                with open(\".\/imgs\/{}.jpg\".format(item[0]), \"wb+\") as f:\n                    f.write(img_data)\n    else:\n        return None\nif __name__ == '__main__':\n    headers = {\n        \"User-Agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/93.0.4577.82 Safari\/537.36\"\n    }\n    url_format = \"http:\/\/www.9thws.com\/#p{}\"\n    urls = [url_format.format(i) for i in range(1, 2)]\n    get_html(urls[0], headers)<\/pre><p>本次代碼測(cè)試輸出采用的?<code>logging<\/code>?模塊實(shí)現(xiàn),效果如下圖所示。 測(cè)試僅采集了 1 頁(yè)數(shù)據(jù),如需擴(kuò)大采集范圍,只需要修改?<code>main<\/code>?函數(shù)內(nèi)頁(yè)碼規(guī)則即可。 ==代碼編寫(xiě)過(guò)程中,發(fā)現(xiàn)數(shù)據(jù)請(qǐng)求是類(lèi)型是 POST,數(shù)據(jù)返回格式是 JSON,所以本案例僅作為 BeautifulSoup 的上手案例吧==?<\/p>\n<p><img src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/168381546946846.png\" alt=\"Comment utiliser le module python beautifulsoup4\"><\/p>"}	</script>
	
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<script>var V_PATH="/";window.onerror=function(){ return true; };</script>
</head>

<body data-commit-time="2023-12-28T14:50:12+08:00" class="editor_body body2_2">
	<link rel="stylesheet" type="text/css" href="/static/csshw/stylehw.css">
<header>
    <div   id="377j5v51b"   class="head">
        <div   id="377j5v51b"   class="haed_left">
            <div   id="377j5v51b"   class="haed_logo">
                <a href="http://www.miracleart.cn/fr/" title="" class="haed_logo_a">
                    <img src="/static/imghw/logo.png" alt="" class="haed_logoimg">
                </a>
            </div>
            <div   id="377j5v51b"   class="head_nav">
                <div   id="377j5v51b"   class="head_navs">
                    <a href="javascript:;" title="communauté" class="head_nava head_nava-template1">communauté</a>
                    <div   class="377j5v51b"   id="dropdown-template1" style="display: none;">
                        <div   id="377j5v51b"   class="languagechoose">
                            <a href="http://www.miracleart.cn/fr/article.html" title="Articles" class="languagechoosea on">Articles</a>
                            <a href="http://www.miracleart.cn/fr/faq/zt" title="Sujets" class="languagechoosea">Sujets</a>
                            <a href="http://www.miracleart.cn/fr/wenda.html" title="Questions et réponses" class="languagechoosea">Questions et réponses</a>
                        </div>
                    </div>
                </div>

                <div   id="377j5v51b"   class="head_navs">
                    <a href="javascript:;" title="Apprendre" class="head_nava head_nava-template1_1">Apprendre</a>
                    <div   class="377j5v51b"   id="dropdown-template1_1" style="display: none;">
                        <div   id="377j5v51b"   class="languagechoose">
                            <a href="http://www.miracleart.cn/fr/course.html" title="Cours" class="languagechoosea on">Cours</a>
                            <a href="http://www.miracleart.cn/fr/dic/" title="Dictionnaire de programmation" class="languagechoosea">Dictionnaire de programmation</a>
                        </div>
                    </div>
                </div>

                <div   id="377j5v51b"   class="head_navs">
                    <a href="javascript:;" title="Bibliothèque d'outils" class="head_nava head_nava-template1_2">Bibliothèque d'outils</a>
                    <div   class="377j5v51b"   id="dropdown-template1_2" style="display: none;">
                        <div   id="377j5v51b"   class="languagechoose">
                            <a href="http://www.miracleart.cn/fr/toolset/development-tools" title="Outils de développement" class="languagechoosea on">Outils de développement</a>
                            <a href="http://www.miracleart.cn/fr/toolset/website-source-code" title="Code source du site Web" class="languagechoosea">Code source du site Web</a>
                            <a href="http://www.miracleart.cn/fr/toolset/php-libraries" title="Bibliothèques PHP" class="languagechoosea">Bibliothèques PHP</a>
                            <a href="http://www.miracleart.cn/fr/toolset/js-special-effects" title="Effets spéciaux JS" class="languagechoosea on">Effets spéciaux JS</a>
                            <a href="http://www.miracleart.cn/fr/toolset/website-materials" title="Matériel du site Web" class="languagechoosea on">Matériel du site Web</a>
                            <a href="http://www.miracleart.cn/fr/toolset/extension-plug-ins" title="Plugins d'extension" class="languagechoosea on">Plugins d'extension</a>
                        </div>
                    </div>
                </div>

                <div   id="377j5v51b"   class="head_navs">
                    <a href="http://www.miracleart.cn/fr/ai" title="Outils d'IA" class="head_nava head_nava-template1_3">Outils d'IA</a>
                </div>

                <div   id="377j5v51b"   class="head_navs">
                    <a href="javascript:;" title="Loisirs" class="head_nava head_nava-template1_3">Loisirs</a>
                    <div   class="377j5v51b"   id="dropdown-template1_3" style="display: none;">
                        <div   id="377j5v51b"   class="languagechoose">
                            <a href="http://www.miracleart.cn/fr/game" title="Téléchargement du jeu" class="languagechoosea on">Téléchargement du jeu</a>
                            <a href="http://www.miracleart.cn/fr/mobile-game-tutorial/" title="Tutoriels de jeu" class="languagechoosea">Tutoriels de jeu</a>

                        </div>
                    </div>
                </div>
            </div>
        </div>
                    <div   id="377j5v51b"   class="head_search">
                <input id="key_words"  onkeydown="if (event.keyCode == 13) searchs('fr')" class="search-input" type="text" autocomplete="off" name="keywords" required="required" placeholder="Block,address,transaction,news" value="">
                <a href="javascript:;" title="recherche"  onclick="searchs('fr')"><img src="/static/imghw/find.png" alt="recherche"></a>
            </div>
                <div   id="377j5v51b"   class="head_right">
            <div   id="377j5v51b"   class="haed_language">
                <a href="javascript:;" class="layui-btn haed_language_btn">Fran?ais<i class="layui-icon layui-icon-triangle-d"></i></a>
                <div   class="377j5v51b"   id="dropdown-template" style="display: none;">
                    <div   id="377j5v51b"   class="languagechoose">
                                                <a href="javascript:setlang('zh-cn');" title="簡(jiǎn)體中文" class="languagechoosea">簡(jiǎn)體中文</a>
                                                <a href="javascript:setlang('en');" title="English" class="languagechoosea">English</a>
                                                <a href="javascript:setlang('zh-tw');" title="繁體中文" class="languagechoosea">繁體中文</a>
                                                <a href="javascript:setlang('ja');" title="日本語(yǔ)" class="languagechoosea">日本語(yǔ)</a>
                                                <a href="javascript:setlang('ko');" title="???" class="languagechoosea">???</a>
                                                <a href="javascript:setlang('ms');" title="Melayu" class="languagechoosea">Melayu</a>
                                                <a href="javascript:;" title="Fran?ais" class="languagechoosea">Fran?ais</a>
                                                <a href="javascript:setlang('de');" title="Deutsch" class="languagechoosea">Deutsch</a>
                                            </div>
                </div>
            </div>
            <span id="377j5v51b"    class="head_right_line"></span>
                            <div style="display: block;" id="login" class="haed_login ">
                    <a href="javascript:;"  title="Login" class="haed_logina ">Login</a>
                </div>
                <div style="display: block;" id="reg" class="head_signup login">
                    <a href="javascript:;"  title="singup" class="head_signupa">singup</a>
                </div>
            
        </div>
    </div>
</header>

	
	<main>
		<div   id="377j5v51b"   class="Article_Details_main">
			<div   id="377j5v51b"   class="Article_Details_main1">
							<div   id="377j5v51b"   class="Article_Details_main1L">
					<div   id="377j5v51b"   class="Article_Details_main1Lmain" id="Article_Details_main1Lmain">
						<div   id="377j5v51b"   class="Article_Details_main1L1">Table des matières</div>
						<div   id="377j5v51b"   class="Article_Details_main1L2" id="Article_Details_main1L2">
							<!-- 左側(cè)懸浮,文章定位標(biāo)題1 id="Article_Details_main1L2s_1"-->
															<div   id="377j5v51b"   class="Article_Details_main1L2s ">
									<a href="#Supplément-de-connaissances-de-base-de-BeautifulSoup" title="1. Supplément de connaissances de base de BeautifulSoup4" >1. Supplément de connaissances de base de BeautifulSoup4</a>
								</div>
																<div   id="377j5v51b"   class="Article_Details_main1L2s ">
									<a href="#二-爬蟲(chóng)案例" title="二、爬蟲(chóng)案例" >二、爬蟲(chóng)案例</a>
								</div>
														</div>
					</div>
				</div>
							<div   id="377j5v51b"   class="Article_Details_main1M">
					<div   id="377j5v51b"   class="phpgenera_Details_mainL1">
						<a href="http://www.miracleart.cn/fr/" title="Maison"
							class="phpgenera_Details_mainL1a">Maison</a>
						<img src="/static/imghw/top_right.png" alt="" />
												<a href="http://www.miracleart.cn/fr/be/"
							class="phpgenera_Details_mainL1a">développement back-end</a>
						<img src="/static/imghw/top_right.png" alt="" />
												<a href="http://www.miracleart.cn/fr/python-tutorials.html"
							class="phpgenera_Details_mainL1a">Tutoriel Python</a>
						<img src="/static/imghw/top_right.png" alt="" />
						<span>Comment utiliser le module python beautifulsoup4</span>
					</div>
					
					<div   id="377j5v51b"   class="Articlelist_txts">
						<div   id="377j5v51b"   class="Articlelist_txts_info">
							<h1 class="Articlelist_txts_title">Comment utiliser le module python beautifulsoup4</h1>
							<div   id="377j5v51b"   class="Articlelist_txts_info_head">
								<div   id="377j5v51b"   class="author_info">
									<a href="http://www.miracleart.cn/fr/member/465014.html"  class="author_avatar">
									<img class="lazy"  data-src="https://img.php.cn/upload/avatar/000/465/014/627b58ba8fa6c600.jpg" src="/static/imghw/default1.png" alt="王林">
									</a>
									<div   id="377j5v51b"   class="author_detail">
																			<a href="http://www.miracleart.cn/fr/member/465014.html" class="author_name">王林</a>
                                										</div>
								</div>
                			</div>
							<span id="377j5v51b"    class="Articlelist_txts_time">May 11, 2023 pm	 10:31 PM</span>
															<div   id="377j5v51b"   class="Articlelist_txts_infos">
																			<span id="377j5v51b"    class="Articlelist_txts_infoss on">python</span>
																			<span id="377j5v51b"    class="Articlelist_txts_infoss ">beautifulsoup4</span>
																	</div>
														
						</div>
					</div>
					<hr />
					<div   id="377j5v51b"   class="article_main php-article">
						<div   id="377j5v51b"   class="article-list-left detail-content-wrap content">
						<ins class="adsbygoogle"
							style="display:block; text-align:center;"
							data-ad-layout="in-article"
							data-ad-format="fluid"
							data-ad-client="ca-pub-5902227090019525"
							data-ad-slot="3461856641">
						</ins>
						

					<h3 id="Supplément-de-connaissances-de-base-de-BeautifulSoup">1. Supplément de connaissances de base de BeautifulSoup4</h3>
<p><code>BeautifulSoup4</code> est une bibliothèque d'analyse Python, principalement utilisée pour analyser le HTML et le XML dans le système de connaissances des robots. more More, <code>BeautifulSoup4</code>?是一款 python 解析庫(kù),主要用于解析 HTML 和 XML,在爬蟲(chóng)知識(shí)體系中解析 HTML 會(huì)比較多一些,</p>
<p><strong>該庫(kù)安裝命令如下:</strong></p><pre class='brush:php;toolbar:false;'>pip install beautifulsoup4</pre><p><code>BeautifulSoup</code> 在解析數(shù)據(jù)時(shí),需依賴(lài)第三方解析器,<strong>常用解析器與優(yōu)勢(shì)如下所示:</strong></p><ul class=" list-paddingleft-2"><li><p><code>python 標(biāo)準(zhǔn)庫(kù) html.parser</code>:python 內(nèi)置標(biāo)準(zhǔn)庫(kù),容錯(cuò)能力強(qiáng);</p></li><li><p><code>lxml 解析器</code>:速度快,容錯(cuò)能力強(qiáng);</p></li><li><p><code>html5lib</code>:容錯(cuò)性最強(qiáng),解析方式與瀏覽器一致。</p></li></ul><p>接下來(lái)用一段自定義的 HTML 代碼來(lái)演示 <code>beautifulsoup4</code> 庫(kù)的基本使用,測(cè)試代碼如下:</p><pre class='brush:php;toolbar:false;'><html>
  <head>
    <title>測(cè)試bs4模塊腳本</title>
  </head>
  <body>
    <h2>橡皮擦的爬蟲(chóng)課</h2>
    <p>用一段自定義的 HTML 代碼來(lái)演示</p>
  </body>
</html></pre><p>使用 <code>BeautifulSoup</code> 對(duì)其進(jìn)行簡(jiǎn)單的操作,包含實(shí)例化 BS 對(duì)象,輸出頁(yè)面標(biāo)簽等內(nèi)容。</p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
text_str = """<html>
	<head>
		<title>測(cè)試bs4模塊腳本</title>
	</head>
	<body>
		<h2>橡皮擦的爬蟲(chóng)課</h2>
		<p>用1段自定義的 HTML 代碼來(lái)演示</p>
		<p>用2段自定義的 HTML 代碼來(lái)演示</p>
	</body>
</html>
"""
# 實(shí)例化 Beautiful Soup 對(duì)象
soup = BeautifulSoup(text_str, "html.parser")
# 上述是將字符串格式化為 Beautiful Soup 對(duì)象,你可以從一個(gè)文件進(jìn)行格式化
# soup = BeautifulSoup(open(&#39;test.html&#39;))
print(soup)
# 輸入網(wǎng)頁(yè)標(biāo)題 title 標(biāo)簽
print(soup.title)
# 輸入網(wǎng)頁(yè) head 標(biāo)簽
print(soup.head)

# 測(cè)試輸入段落標(biāo)簽 p
print(soup.p) # 默認(rèn)獲取第一個(gè)</pre><p>我們可以通過(guò) BeautifulSoup 對(duì)象,直接調(diào)用網(wǎng)頁(yè)標(biāo)簽,這里存在一個(gè)問(wèn)題,通過(guò) BS 對(duì)象調(diào)用標(biāo)簽只能獲取排在第一位置上的標(biāo)簽,如上述代碼中,只獲取到了一個(gè) <code>p</code> 標(biāo)簽,如果想要獲取更多內(nèi)容,請(qǐng)繼續(xù)閱讀。</p><p><strong>學(xué)習(xí)到這里,我們需要了解 BeautifulSoup 中的 4 個(gè)內(nèi)置對(duì)象:</strong></p><ul class=" list-paddingleft-2"><li><p><code>BeautifulSoup</code>:基本對(duì)象,整個(gè) HTML 對(duì)象,一般當(dāng)做 Tag 對(duì)象看即可;</p></li><li><p><code>Tag</code>:標(biāo)簽對(duì)象,標(biāo)簽就是網(wǎng)頁(yè)中的各個(gè)節(jié)點(diǎn),例如 title,head,p;</p></li><li><p><code>NavigableString</code>:標(biāo)簽內(nèi)部字符串;</p></li><li><p><code>Comment</code>:注釋對(duì)象,爬蟲(chóng)里面使用場(chǎng)景不多。</p></li></ul><p><strong>下述代碼為你演示這幾種對(duì)象出現(xiàn)的場(chǎng)景,注意代碼中的相關(guān)注釋?zhuān)?/strong></p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
text_str = """<html>
	<head>
		<title>測(cè)試bs4模塊腳本</title>
	</head>
	<body>
		<h2>橡皮擦的爬蟲(chóng)課</h2>
		<p>用1段自定義的 HTML 代碼來(lái)演示</p>
		<p>用2段自定義的 HTML 代碼來(lái)演示</p>
	</body>
</html>
"""
# 實(shí)例化 Beautiful Soup 對(duì)象
soup = BeautifulSoup(text_str, "html.parser")
# 上述是將字符串格式化為 Beautiful Soup 對(duì)象,你可以從一個(gè)文件進(jìn)行格式化
# soup = BeautifulSoup(open(&#39;test.html&#39;))
print(soup)
print(type(soup))  # <class &#39;bs4.BeautifulSoup&#39;>
# 輸入網(wǎng)頁(yè)標(biāo)題 title 標(biāo)簽
print(soup.title)
print(type(soup.title)) # <class &#39;bs4.element.Tag&#39;>
print(type(soup.title.string)) # <class &#39;bs4.element.NavigableString&#39;>
# 輸入網(wǎng)頁(yè) head 標(biāo)簽
print(soup.head)</pre><p><strong>對(duì)于 <strong>Tag 對(duì)象</strong>,有兩個(gè)重要的屬性,是 <code>name</code> 和 <code>attrs</code></strong></p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
text_str = """<html>
	<head>
		<title>測(cè)試bs4模塊腳本</title>
	</head>
	<body>
		<h2>橡皮擦的爬蟲(chóng)課</h2>
		<p>用1段自定義的 HTML 代碼來(lái)演示</p>
		<p>用2段自定義的 HTML 代碼來(lái)演示</p>
		<a href="http://www.csdn.net" rel="external nofollow"  rel="external nofollow" >CSDN 網(wǎng)站</a>
	</body>
</html>
"""
# 實(shí)例化 Beautiful Soup 對(duì)象
soup = BeautifulSoup(text_str, "html.parser")
print(soup.name) # [document]
print(soup.title.name) # 獲取標(biāo)簽名 title
print(soup.html.body.a) # 可以通過(guò)標(biāo)簽層級(jí)獲取下層標(biāo)簽
print(soup.body.a) # html 作為一個(gè)特殊的根標(biāo)簽,可以省略
print(soup.p.a) # 無(wú)法獲取到 a 標(biāo)簽
print(soup.a.attrs) # 獲取屬性</pre><p>上述代碼演示了獲取 <code>name</code> 屬性和 <code>attrs</code> 屬性的用法,其中 <code>attrs</code> 屬性得到的是一個(gè)字典,可以通過(guò)鍵獲取對(duì)應(yīng)的值。</p><p>獲取標(biāo)簽的屬性值,在 BeautifulSoup 中,還可以使用如下方法:</p><pre class='brush:php;toolbar:false;'>print(soup.a["href"])
print(soup.a.get("href"))</pre><p><strong>獲取 <code>NavigableString</code> 對(duì)象</strong> 獲取了網(wǎng)頁(yè)標(biāo)簽之后,就要獲取標(biāo)簽內(nèi)文本了,通過(guò)下述代碼進(jìn)行。</p><pre class='brush:php;toolbar:false;'>print(soup.a.string)</pre><p>除此之外,你還可以使用 <code>text</code> 屬性和 <code>get_text()</code> 方法獲取標(biāo)簽內(nèi)容。</p><pre class='brush:php;toolbar:false;'>print(soup.a.string)
print(soup.a.text)
print(soup.a.get_text())</pre><p>還可以獲取標(biāo)簽內(nèi)所有文本,使用 <code>strings</code> 和 <code>stripped_strings</code> 即可。</p><pre class='brush:php;toolbar:false;'>print(list(soup.body.strings)) # 獲取到空格或者換行
print(list(soup.body.stripped_strings)) # 去除空格或者換行</pre><p><strong>擴(kuò)展標(biāo)簽/節(jié)點(diǎn)選擇器之遍歷文檔樹(shù)</strong></p><p>直接子節(jié)點(diǎn)</p><p>標(biāo)簽(Tag)對(duì)象的直接子元素,可以使用 <code>contents</code> 和 <code>children</code> 屬性獲取。</p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
text_str = """<html>
	<head>
		<title>測(cè)試bs4模塊腳本</title>
	</head>
	<body>
		<div id="content">
			<h2>橡皮擦的爬蟲(chóng)課<span>最棒</span></h2>
            <p>用1段自定義的 HTML 代碼來(lái)演示</p>
            <p>用2段自定義的 HTML 代碼來(lái)演示</p>
            <a href="http://www.csdn.net" rel="external nofollow"  rel="external nofollow" >CSDN 網(wǎng)站</a>
		</div>
        <ul class="nav">
            <li>首頁(yè)</li>
            <li>博客</li>
            <li>專(zhuān)欄課程</li>
        </ul>

	</body>
</html>
"""
# 實(shí)例化 Beautiful Soup 對(duì)象
soup = BeautifulSoup(text_str, "html.parser")
# contents 屬性獲取節(jié)點(diǎn)的直接子節(jié)點(diǎn),以列表的形式返回內(nèi)容
print(soup.div.contents) # 返回列表
# children 屬性獲取的也是節(jié)點(diǎn)的直接子節(jié)點(diǎn),以生成器的類(lèi)型返回
print(soup.div.children) # 返回 <list_iterator object at 0x00000111EE9B6340></pre><p>請(qǐng)注意以上兩個(gè)屬性獲取的都是<strong>直接</strong>子節(jié)點(diǎn),例如 <code>h2</code> 標(biāo)簽內(nèi)的后代標(biāo)簽 <code>span</code> ,不會(huì)單獨(dú)獲取到。</p><p>如果希望將所有的標(biāo)簽都獲取到,使用 <code>descendants</code> 屬性,它返回的是一個(gè)生成器,所有標(biāo)簽包括標(biāo)簽內(nèi)的文本都會(huì)單獨(dú)獲取。</p><pre class='brush:php;toolbar:false;'>print(list(soup.div.descendants))</pre><p>其它節(jié)點(diǎn)的獲?。私饧纯?,即查即用)</p><ul class=" list-paddingleft-2"><li><p><code>parent</code> 和 <code>parents</code>:直接父節(jié)點(diǎn)和所有父節(jié)點(diǎn);</p></li><li><p><code>next_sibling</code>,<code>next_siblings</code>,<code>previous_sibling</code>,<code>previous_siblings</code>:分別表示下一個(gè)兄弟節(jié)點(diǎn)、下面所有兄弟節(jié)點(diǎn)、上一個(gè)兄弟節(jié)點(diǎn)、上面所有兄弟節(jié)點(diǎn),由于換行符也是一個(gè)節(jié)點(diǎn),所有在使用這幾個(gè)屬性時(shí),要注意一下?lián)Q行符;</p></li><li><p><code>next_element</code>,<code>next_elements</code>,<code>previous_element</code>,<code>previous_elements</code>:這幾個(gè)屬性分別表示上一個(gè)節(jié)點(diǎn)或者下一個(gè)節(jié)點(diǎn),注意它們不分層次,而是針對(duì)所有節(jié)點(diǎn),例如上述代碼中 <code>div</code> 節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)是 <code>h2</code>,而 <code>div</code> 節(jié)點(diǎn)的兄弟節(jié)點(diǎn)是 <code>ul</code>。</p></li></ul><p><strong>文檔樹(shù)搜索相關(guān)函數(shù)</strong></p><p>第一個(gè)要學(xué)習(xí)的函數(shù)就是 <code>find_all()</code> 函數(shù),<strong>原型如下所示:</strong></p><pre class='brush:php;toolbar:false;'>find_all(name,attrs,recursive,text,limit=None,**kwargs)</pre><ul class=" list-paddingleft-2"><li><p><code>name</code>:該參數(shù)為 tag 標(biāo)簽的名字,例如 <code>find_all(&#39;p&#39;)</code> 是查找所有的 <code>p</code></p><strong>La commande d'installation de la bibliothèque est la suivante?:</strong>#????#<pre class='brush:php;toolbar:false;'>print(soup.find_all(&#39;li&#39;)) # 獲取所有的 li
print(soup.find_all(attrs={&#39;class&#39;: &#39;nav&#39;})) # 傳入 attrs 屬性
print(soup.find_all(re.compile("p"))) # 傳遞正則,實(shí)測(cè)效果不理想
print(soup.find_all([&#39;a&#39;,&#39;p&#39;])) # 傳遞列表</pre>#????#<code>BeautifulSoup</code> Lors de l'analyse des données, vous devez s'appuyer sur des analyseurs tiers,<strong>les analyseurs couramment utilisés et leurs avantages sont les suivants?:</strong>#????#<ul class=" list-paddingleft-2"><li>#????#<code> analyseur standard python html.</code>?: bibliothèque standard intégrée python, forte tolérance aux pannes?; #????#</li><li>#????#<code>analyseur lxml</code>?: rapide, puissant?; tolérance aux pannes?; #?? ??#</li><li>#????#<code>html5lib</code>?: la plus tolérante aux pannes et la méthode d'analyse est cohérente avec le navigateur. #????#</li></ul>#????# Ensuite, utilisez un code HTML personnalisé pour démontrer l'utilisation de base de la bibliothèque <code>beautifulsoup4</code> Le code de test est le suivant?: #????. #<pre class='brush:php;toolbar:false;'>print(soup.body.div.find_all([&#39;a&#39;,&#39;p&#39;],recursive=False)) # 傳遞列表</pre># ????#Utilisez <code>BeautifulSoup</code> pour effectuer des opérations simples dessus, notamment l'instanciation d'objets BS, la sortie de balises de page, etc. #????#<pre class='brush:php;toolbar:false;'>print(soup.find_all(text=&#39;首頁(yè)&#39;)) # [&#39;首頁(yè)&#39;]
print(soup.find_all(text=re.compile("^首"))) # [&#39;首頁(yè)&#39;]
print(soup.find_all(text=["首頁(yè)",re.compile(&#39;課&#39;)])) # [&#39;橡皮擦的爬蟲(chóng)課&#39;, &#39;首頁(yè)&#39;, &#39;專(zhuān)欄課程&#39;]</pre>#????#Nous pouvons appeler directement la balise de page Web via l'objet BeautifulSoup. Il y a un problème ici. L'appel de la balise via l'objet BS ne peut que classer la balise en premier. la balise en première position est obtenue. Une balise <code>p</code>, si vous souhaitez obtenir plus de contenu, veuillez continuer à lire. #????##????#<strong>Après avoir appris cela, nous devons comprendre les 4 objets intégrés dans BeautifulSoup?:</strong>#????#<ul class=" list-paddingleft-2"><li ># ????#<code>BeautifulSoup</code>?: Objet de base, l'objet HTML entier, généralement considéré comme un objet Tag?; #????#</li><li>#????#<code>Tag</?; code> : Objet Label, l'étiquette est chaque n?ud de la page Web, tel que title, head, p; #????#</li><li>#????#<code>NavigableString</code>?: Label internal string; #?? ??#</li><li>#????#<code>Comment</code>?: Objet de commentaire, il n'y a pas beaucoup de scénarios d'utilisation dans les robots. #????#</li></ul>#????#<strong>Le code suivant vous montre les scénarios dans lesquels ces objets apparaissent. Faites attention aux commentaires pertinents dans le code?: </strong>#????#. <pre class='brush:php;toolbar:false;'>print(soup.find_all(class_ = &#39;nav&#39;))
print(soup.find_all(class_ = &#39;nav li&#39;))</pre># ????#<strong>Pour l'<strong>objet Tag</strong>, il existe deux attributs importants, qui sont <code>name</code> et <code>attrs</code></strong>#?? ??# <pre class='brush:php;toolbar:false;'>print(soup.select(&#39;ul[class^="na"]&#39;))</pre>#????#Le code ci-dessus démontre l'utilisation de l'obtention de l'attribut <code>name</code> et de l'attribut <code>attrs</code>. L'attribut <code>attrs</code> obtient un dictionnaire. , qui peut être transmis Key obtient la valeur correspondante. #????##????#Obtenir la valeur d'attribut de la balise Dans BeautifulSoup, vous pouvez également utiliser la méthode suivante : #????#<pre class='brush:php;toolbar:false;'>print(soup.select(&#39;ul[class*="li"]&#39;))</pre>#????#<strong>Obtenir l'objet <code>NavigableString</code>< /strong> Après avoir obtenu la balise de page Web, vous devez obtenir le texte contenu dans la balise, ce qui se fait via le code suivant. #????#<pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
import requests
import logging
logging.basicConfig(level=logging.NOTSET)
def get_html(url, headers) -> None:
    try:
        res = requests.get(url=url, headers=headers, timeout=3)
    except Exception as e:
        logging.debug("采集異常", e)

    if res is not None:
        html_str = res.text
        soup = BeautifulSoup(html_str, "html.parser")
        imgs = soup.find_all(attrs={&#39;class&#39;: &#39;lazy&#39;})
        print("獲取到的數(shù)據(jù)量是", len(imgs))
        datas = []
        for item in imgs:
            name = item.get(&#39;alt&#39;)
            src = item["src"]
            logging.info(f"{name},{src}")
            # 獲取拼接數(shù)據(jù)
            datas.append((name, src))
        save(datas, headers)
def save(datas, headers) -> None:
    if datas is not None:
        for item in datas:
            try:
                # 抓取圖片
                res = requests.get(url=item[1], headers=headers, timeout=5)
            except Exception as e:
                logging.debug(e)

            if res is not None:
                img_data = res.content
                with open("./imgs/{}.jpg".format(item[0]), "wb+") as f:
                    f.write(img_data)
    else:
        return None
if __name__ == &#39;__main__&#39;:
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
    }
    url_format = "http://www.9thws.com/#p{}"
    urls = [url_format.format(i) for i in range(1, 2)]
    get_html(urls[0], headers)</pre>#????#De plus, vous pouvez également utiliser l'attribut <code>text</code> et la méthode <code>get_text()</code> pour obtenir le contenu de la balise. #????#rrreee#????# Vous pouvez également obtenir tout le texte de la balise en utilisant <code>strings</code> et <code>stripped_strings</code>. #????#rrreee#????#<strong>Sélecteur de balise/n?ud étendu traversant l'arborescence du document</strong>#????##????#N?ud enfant direct#????##????#Objet Tag Les éléments enfants directs peut être obtenu en utilisant les attributs <code>contents</code> et <code>children</code>. #????#rrreee#????#Veuillez noter que les deux attributs ci-dessus obtiennent les n?uds enfants <strong>directs</strong>, tels que la balise descendante <code>span</ dans le <code>h2</code> code de balise> ne sera pas obtenu séparément. #????##????#Si vous souhaitez obtenir toutes les balises, utilisez l'attribut <code>descendants</code>. Il renvoie un générateur et toutes les balises, y compris le texte à l'intérieur des balises, seront récupérées séparément. #????#rrreee#????#Acquisition d'autres n?uds (il suffit de comprendre, vérifier et utiliser) #????#<ul class="list-paddingleft-2"><li>#????#<code>parent </ code> et <code>parents</code>?: n?ud parent direct et tous les n?uds parents?; #????#</li><li>#????#<code>next_sibling</code>, <code>next_siblings </ code>, <code>previous_sibling</code>, <code>previous_siblings</code>?: représentent respectivement le n?ud frère suivant, tous les n?uds frères en dessous, le n?ud frère précédent et tous les n?uds frères au-dessus puisque le caractère de nouvelle ligne est également. un n?ud, lorsque vous utilisez ces attributs, veuillez faire attention au saut de ligne #????#</li><li>#????#<code>next_element</code>, <code>next_elements</code>, < code>previous_element</code>, <code>previous_elements</code>?: ces attributs représentent respectivement le n?ud précédent ou le n?ud suivant. Notez qu'ils ne sont pas hiérarchiques, mais ciblent tous les n?uds, comme dans le code ci-dessus <code The. Le n?ud suivant du n?ud >div</code> est <code>h2</code>, et le n?ud frère du n?ud <code>div</code> est <code>ul</code>. #????#</li></ul>#????#<strong>Fonctions liées à la recherche dans l'arborescence des documents</strong>#????##????#La première fonction à apprendre est <code>find_all() </ code>, <strong>le prototype est le suivant : </strong>#????#rrreee<ul class=" list-paddingleft-2"><li>#????#<code>name</code> : Ce paramètre est le nom de la balise. Par exemple, <code>find_all('p')</code> sert à rechercher toutes les balises <code>p</code>. Il peut accepter les cha?nes de nom de balise, les expressions régulières et. listes #????#</li><li><p><code>attrs</code>:傳入的屬性,該參數(shù)可以字典的形式傳入,例如 <code>attrs={&#39;class&#39;: &#39;nav&#39;}</code>,返回的結(jié)果是 tag 類(lèi)型的列表;</p></li></ul><p><strong>上述兩個(gè)參數(shù)的用法示例如下:</strong></p><pre class='brush:php;toolbar:false;'>print(soup.find_all(&#39;li&#39;)) # 獲取所有的 li
print(soup.find_all(attrs={&#39;class&#39;: &#39;nav&#39;})) # 傳入 attrs 屬性
print(soup.find_all(re.compile("p"))) # 傳遞正則,實(shí)測(cè)效果不理想
print(soup.find_all([&#39;a&#39;,&#39;p&#39;])) # 傳遞列表</pre><ul class=" list-paddingleft-2"><li><p><code>recursive</code>:調(diào)用 <code>find_all ()</code> 方法時(shí),BeautifulSoup 會(huì)檢索當(dāng)前 tag 的所有子孫節(jié)點(diǎn),如果只想搜索 tag 的直接子節(jié)點(diǎn),可以使用參數(shù) <code>recursive=False</code>,測(cè)試代碼如下:</p></li></ul><pre class='brush:php;toolbar:false;'>print(soup.body.div.find_all([&#39;a&#39;,&#39;p&#39;],recursive=False)) # 傳遞列表</pre><ul class=" list-paddingleft-2"><li><p><code>text</code>:可以檢索文檔中的文本字符串內(nèi)容,與 <code>name</code> 參數(shù)的可選值一樣,<code>text</code> 參數(shù)接受標(biāo)簽名字符串、正則表達(dá)式、 列表;</p></li></ul><pre class='brush:php;toolbar:false;'>print(soup.find_all(text=&#39;首頁(yè)&#39;)) # [&#39;首頁(yè)&#39;]
print(soup.find_all(text=re.compile("^首"))) # [&#39;首頁(yè)&#39;]
print(soup.find_all(text=["首頁(yè)",re.compile(&#39;課&#39;)])) # [&#39;橡皮擦的爬蟲(chóng)課&#39;, &#39;首頁(yè)&#39;, &#39;專(zhuān)欄課程&#39;]</pre><ul class=" list-paddingleft-2"><li><p><code>limit</code>:可以用來(lái)限制返回結(jié)果的數(shù)量;</p></li><li><p><code>kwargs</code>:如果一個(gè)指定名字的參數(shù)不是搜索內(nèi)置的參數(shù)名,搜索時(shí)會(huì)把該參數(shù)當(dāng)作 tag 的屬性來(lái)搜索。這里要按 <code>class</code> 屬性搜索,因?yàn)?<code>class</code> 是 python 的保留字,需要寫(xiě)作 <code>class_</code>,按 <code>class_</code> 查找時(shí),只要一個(gè) CSS 類(lèi)名滿(mǎn)足即可,如需多個(gè) CSS 名稱(chēng),填寫(xiě)順序需要與標(biāo)簽一致。</p></li></ul><pre class='brush:php;toolbar:false;'>print(soup.find_all(class_ = &#39;nav&#39;))
print(soup.find_all(class_ = &#39;nav li&#39;))</pre><p>還需要注意網(wǎng)頁(yè)節(jié)點(diǎn)中,有些屬性在搜索中不能作為<code>kwargs</code>參數(shù)使用,比如<code>html5</code> 中的 <code>data-*</code>屬性,需要通過(guò)<code>attrs</code>參數(shù)進(jìn)行匹配。</p><blockquote><p>與 <code>find_all()</code>方法用戶(hù)基本一致的其它方法清單如下:</p></blockquote><ul class=" list-paddingleft-2"><li><p><code>find()</code>:函數(shù)原型<code>find( name , attrs , recursive , text , **kwargs )</code>,返回一個(gè)匹配元素;</p></li><li><p><code>find_parents(),find_parent()</code>:函數(shù)原型 <code>find_parent(self, name=None, attrs={}, **kwargs)</code>,返回當(dāng)前節(jié)點(diǎn)的父級(jí)節(jié)點(diǎn);</p></li><li><p><code>find_next_siblings(),find_next_sibling()</code>:函數(shù)原型 <code>find_next_sibling(self, name=None, attrs={}, text=None, **kwargs)</code>,返回當(dāng)前節(jié)點(diǎn)的下一兄弟節(jié)點(diǎn);</p></li><li><p><code>find_previous_siblings(),find_previous_sibling()</code>:同上,返回當(dāng)前的節(jié)點(diǎn)的上一兄弟節(jié)點(diǎn);</p></li><li><p><code>find_all_next(),find_next(),find_all_previous () ,find_previous ()</code>:函數(shù)原型 <code>find_all_next(self, name=None, attrs={}, text=None, limit=None, **kwargs)</code>,檢索當(dāng)前節(jié)點(diǎn)的后代節(jié)點(diǎn)。</p></li></ul><p><strong>CSS 選擇器</strong> 該小節(jié)的知識(shí)點(diǎn)與<code>pyquery</code>有點(diǎn)撞車(chē),核心使用<code>select()</code>方法即可實(shí)現(xiàn),返回?cái)?shù)據(jù)是列表元組。</p><ul class=" list-paddingleft-2"><li><p>通過(guò)標(biāo)簽名查找,<code>soup.select("title")</code>;</p></li><li><p>通過(guò)類(lèi)名查找,<code>soup.select(".nav")</code>;</p></li><li><p>通過(guò) id 名查找,<code>soup.select("#content")</code>;</p></li><li><p>通過(guò)組合查找,<code>soup.select("div#content")</code>;</p></li><li><p>通過(guò)屬性查找,<code>soup.select("div[id=&#39;content&#39;")</code>,<code>soup.select("a[href]")</code>;</p></li></ul><p>在通過(guò)屬性查找時(shí),還有一些技巧可以使用,<strong>例如:</strong></p><ul class=" list-paddingleft-2"><li><p><code>^=</code>:可以獲取以 XX 開(kāi)頭的節(jié)點(diǎn):</p></li></ul><pre class='brush:php;toolbar:false;'>print(soup.select(&#39;ul[class^="na"]&#39;))</pre><ul class=" list-paddingleft-2"><li><p><code>*=</code>:獲取屬性包含指定字符的節(jié)點(diǎn):</p></li></ul><pre class='brush:php;toolbar:false;'>print(soup.select(&#39;ul[class*="li"]&#39;))</pre><h3 id="二-爬蟲(chóng)案例">二、爬蟲(chóng)案例</h3><p>BeautifulSoup 的基礎(chǔ)知識(shí)掌握之后,在進(jìn)行爬蟲(chóng)案例的編寫(xiě),就非常簡(jiǎn)單了,本次要采集的目標(biāo)網(wǎng)站 ,該目標(biāo)網(wǎng)站有大量的藝術(shù)二維碼,可以供設(shè)計(jì)大哥做參考。</p><p><img src="/static/imghw/default1.png"  data-src="https://img.php.cn/upload/article/000/465/014/168381546889285.png"  class="lazy" alt="Comment utiliser le module python beautifulsoup4" /></p><p><strong>下述應(yīng)用到了 BeautifulSoup 模塊的標(biāo)簽檢索與屬性檢索,完整代碼如下:</strong></p><pre class='brush:php;toolbar:false;'>from bs4 import BeautifulSoup
import requests
import logging
logging.basicConfig(level=logging.NOTSET)
def get_html(url, headers) -> None:
    try:
        res = requests.get(url=url, headers=headers, timeout=3)
    except Exception as e:
        logging.debug("采集異常", e)

    if res is not None:
        html_str = res.text
        soup = BeautifulSoup(html_str, "html.parser")
        imgs = soup.find_all(attrs={&#39;class&#39;: &#39;lazy&#39;})
        print("獲取到的數(shù)據(jù)量是", len(imgs))
        datas = []
        for item in imgs:
            name = item.get(&#39;alt&#39;)
            src = item["src"]
            logging.info(f"{name},{src}")
            # 獲取拼接數(shù)據(jù)
            datas.append((name, src))
        save(datas, headers)
def save(datas, headers) -> None:
    if datas is not None:
        for item in datas:
            try:
                # 抓取圖片
                res = requests.get(url=item[1], headers=headers, timeout=5)
            except Exception as e:
                logging.debug(e)

            if res is not None:
                img_data = res.content
                with open("./imgs/{}.jpg".format(item[0]), "wb+") as f:
                    f.write(img_data)
    else:
        return None
if __name__ == &#39;__main__&#39;:
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
    }
    url_format = "http://www.9thws.com/#p{}"
    urls = [url_format.format(i) for i in range(1, 2)]
    get_html(urls[0], headers)</pre><p>本次代碼測(cè)試輸出采用的?<code>logging</code>?模塊實(shí)現(xiàn),效果如下圖所示。 測(cè)試僅采集了 1 頁(yè)數(shù)據(jù),如需擴(kuò)大采集范圍,只需要修改?<code>main</code>?函數(shù)內(nèi)頁(yè)碼規(guī)則即可。 ==代碼編寫(xiě)過(guò)程中,發(fā)現(xiàn)數(shù)據(jù)請(qǐng)求是類(lèi)型是 POST,數(shù)據(jù)返回格式是 JSON,所以本案例僅作為 BeautifulSoup 的上手案例吧==?</p>
<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/465/014/168381546946846.png" class="lazy" alt="Comment utiliser le module python beautifulsoup4"></p><p>Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!</p>


						</div>
					</div>
					<div   id="377j5v51b"   class="wzconShengming_sp">
						<div   id="377j5v51b"   class="bzsmdiv_sp">Déclaration de ce site Web</div>
						<div>Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefa?on, veuillez contacter admin@php.cn</div>
					</div>
				</div>

				<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5902227090019525"
     data-ad-slot="2507867629"></ins>



				<div   id="377j5v51b"   class="AI_ToolDetails_main4sR">


				<ins class="adsbygoogle"
        style="display:block"
        data-ad-client="ca-pub-5902227090019525"
        data-ad-slot="3653428331"
        data-ad-format="auto"
        data-full-width-responsive="true"></ins>
    


					<!-- <div   id="377j5v51b"   class="phpgenera_Details_mainR4">
						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									src="/static/imghw/hotarticle2.png" alt="" />
								<h2>Article chaud</h2>
							</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796832397.html" title="Guide de construction de Grass Wonder | Uma musume joli derby" class="phpgenera_Details_mainR4_bottom_title">Guide de construction de Grass Wonder | Uma musume joli derby</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796833110.html" title="<??>: 99 nuits dans la forêt - tous les badges et comment les déverrouiller" class="phpgenera_Details_mainR4_bottom_title"><??>: 99 nuits dans la forêt - tous les badges et comment les déverrouiller</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>4 Il y a quelques semaines</span>
										<span>By DDD</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796831605.html" title="Uma Musume Pretty Derby Banner Schedule (juillet 2025)" class="phpgenera_Details_mainR4_bottom_title">Uma Musume Pretty Derby Banner Schedule (juillet 2025)</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796836699.html" title="Guide de température de Rimworld Odyssey pour les navires et Gravtech" class="phpgenera_Details_mainR4_bottom_title">Guide de température de Rimworld Odyssey pour les navires et Gravtech</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>3 Il y a quelques semaines</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796831905.html" title="Windows Security est vide ou ne montre pas les options" class="phpgenera_Details_mainR4_bottom_title">Windows Security est vide ou ne montre pas les options</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By 下次還敢</span>
									</div>
								</div>
														</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
								<a href="http://www.miracleart.cn/fr/article.html">Afficher plus</a>
							</div>
						</div>
					</div> -->


											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/hottools2.png" alt="" />
									<h2>Outils d'IA chauds</h2>
								</div>
								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173410641626608.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undress AI Tool" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/ai/undress-ai-tool" title="Undress AI Tool" class="phpmain_tab2_mids_title">
													<h3>Undress AI Tool</h3>
												</a>
												<p>Images de déshabillage gratuites</p>
											</div>
										</div>
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411540686492.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Undresser.AI Undress" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/ai/undresserai-undress" title="Undresser.AI Undress" class="phpmain_tab2_mids_title">
													<h3>Undresser.AI Undress</h3>
												</a>
												<p>Application basée sur l'IA pour créer des photos de nu réalistes</p>
											</div>
										</div>
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411552797167.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="AI Clothes Remover" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/ai/ai-clothes-remover" title="AI Clothes Remover" class="phpmain_tab2_mids_title">
													<h3>AI Clothes Remover</h3>
												</a>
												<p>Outil d'IA en ligne pour supprimer les vêtements des photos.</p>
											</div>
										</div>
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173411529149311.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Clothoff.io" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/ai/clothoffio" title="Clothoff.io" class="phpmain_tab2_mids_title">
													<h3>Clothoff.io</h3>
												</a>
												<p>Dissolvant de vêtements AI</p>
											</div>
										</div>
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/ai_manual/001/246/273/173414504068133.jpg?x-oss-process=image/resize,m_fill,h_50,w_50" src="/static/imghw/default1.png" alt="Video Face Swap" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/ai/video-swap" title="Video Face Swap" class="phpmain_tab2_mids_title">
													<h3>Video Face Swap</h3>
												</a>
												<p>échangez les visages dans n'importe quelle vidéo sans effort grace à notre outil d'échange de visage AI entièrement gratuit?!</p>
											</div>
										</div>
																</div>
								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
									<a href="http://www.miracleart.cn/fr/ai">Afficher plus</a>
								</div>
							</div>
						</div>
					


					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									src="/static/imghw/hotarticle2.png" alt="" />
								<h2>Article chaud</h2>
							</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796832397.html" title="Guide de construction de Grass Wonder | Uma musume joli derby" class="phpgenera_Details_mainR4_bottom_title">Guide de construction de Grass Wonder | Uma musume joli derby</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796833110.html" title="<??>: 99 nuits dans la forêt - tous les badges et comment les déverrouiller" class="phpgenera_Details_mainR4_bottom_title"><??>: 99 nuits dans la forêt - tous les badges et comment les déverrouiller</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>4 Il y a quelques semaines</span>
										<span>By DDD</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796831605.html" title="Uma Musume Pretty Derby Banner Schedule (juillet 2025)" class="phpgenera_Details_mainR4_bottom_title">Uma Musume Pretty Derby Banner Schedule (juillet 2025)</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796836699.html" title="Guide de température de Rimworld Odyssey pour les navires et Gravtech" class="phpgenera_Details_mainR4_bottom_title">Guide de température de Rimworld Odyssey pour les navires et Gravtech</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>3 Il y a quelques semaines</span>
										<span>By Jack chen</span>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/1796831905.html" title="Windows Security est vide ou ne montre pas les options" class="phpgenera_Details_mainR4_bottom_title">Windows Security est vide ou ne montre pas les options</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<span>1 Il y a quelques mois</span>
										<span>By 下次還敢</span>
									</div>
								</div>
														</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
								<a href="http://www.miracleart.cn/fr/article.html">Afficher plus</a>
							</div>
						</div>
					</div>


											<div   id="377j5v51b"   class="phpgenera_Details_mainR3">
							<div   id="377j5v51b"   class="phpmain1_4R_readrank">
								<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/hottools2.png" alt="" />
									<h2>Outils chauds</h2>
								</div>
								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_bottom">
																		<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/toolset/development-tools/92" title="Bloc-notes++7.3.1" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab96f0f39f7357.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Bloc-notes++7.3.1" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/toolset/development-tools/92" title="Bloc-notes++7.3.1" class="phpmain_tab2_mids_title">
													<h3>Bloc-notes++7.3.1</h3>
												</a>
												<p>éditeur de code facile à utiliser et gratuit</p>
											</div>
										</div>
																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/toolset/development-tools/93" title="SublimeText3 version chinoise" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97a3baad9677.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 version chinoise" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/toolset/development-tools/93" title="SublimeText3 version chinoise" class="phpmain_tab2_mids_title">
													<h3>SublimeText3 version chinoise</h3>
												</a>
												<p>Version chinoise, très simple à utiliser</p>
											</div>
										</div>
																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/toolset/development-tools/121" title="Envoyer Studio 13.0.1" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58ab97ecd1ab2670.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Envoyer Studio 13.0.1" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/toolset/development-tools/121" title="Envoyer Studio 13.0.1" class="phpmain_tab2_mids_title">
													<h3>Envoyer Studio 13.0.1</h3>
												</a>
												<p>Puissant environnement de développement intégré PHP</p>
											</div>
										</div>
																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d0e0fc74683535.jpg?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="Dreamweaver CS6" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/toolset/development-tools/469" title="Dreamweaver CS6" class="phpmain_tab2_mids_title">
													<h3>Dreamweaver CS6</h3>
												</a>
												<p>Outils de développement Web visuel</p>
											</div>
										</div>
																			<div   id="377j5v51b"   class="phpmain_tab2_mids_top">
											<a href="http://www.miracleart.cn/fr/toolset/development-tools/500" title="SublimeText3 version Mac" class="phpmain_tab2_mids_top_img">
												<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
													class="lazy"  data-src="https://img.php.cn/upload/manual/000/000/001/58d34035e2757995.png?x-oss-process=image/resize,m_fill,h_50,w_72" src="/static/imghw/default1.png" alt="SublimeText3 version Mac" />
											</a>
											<div   id="377j5v51b"   class="phpmain_tab2_mids_info">
												<a href="http://www.miracleart.cn/fr/toolset/development-tools/500" title="SublimeText3 version Mac" class="phpmain_tab2_mids_title">
													<h3>SublimeText3 version Mac</h3>
												</a>
												<p>Logiciel d'édition de code au niveau de Dieu (SublimeText3)</p>
											</div>
										</div>
																	</div>
								<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
									<a href="http://www.miracleart.cn/fr/ai">Afficher plus</a>
								</div>
							</div>
						</div>
										

					
					<div   id="377j5v51b"   class="phpgenera_Details_mainR4">
						<div   id="377j5v51b"   class="phpmain1_4R_readrank">
							<div   id="377j5v51b"   class="phpmain1_4R_readrank_top">
								<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
									src="/static/imghw/hotarticle2.png" alt="" />
								<h2>Sujets chauds</h2>
							</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottom">
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/laravel-tutori" title="Tutoriel Laravel" class="phpgenera_Details_mainR4_bottom_title">Tutoriel Laravel</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
											<img src="/static/imghw/eyess.png" alt="" />
											<span>1601</span>
										</div>
										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
											<img src="/static/imghw/tiezi.png" alt="" />
											<span>29</span>
										</div>
									</div>
								</div>
															<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms">
									<a href="http://www.miracleart.cn/fr/faq/php-tutorial" title="Tutoriel PHP" class="phpgenera_Details_mainR4_bottom_title">Tutoriel PHP</a>
									<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_info">
										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
											<img src="/static/imghw/eyess.png" alt="" />
											<span>1502</span>
										</div>
										<div   id="377j5v51b"   class="phpgenera_Details_mainR4_bottoms_infos">
											<img src="/static/imghw/tiezi.png" alt="" />
											<span>276</span>
										</div>
									</div>
								</div>
														</div>
							<div   id="377j5v51b"   class="phpgenera_Details_mainR3_more">
								<a href="http://www.miracleart.cn/fr/faq/zt">Afficher plus</a>
							</div>
						</div>
					</div>
				</div>
			</div>
							<div   id="377j5v51b"   class="Article_Details_main2">
					<div   id="377j5v51b"   class="phpgenera_Details_mainL4">
						<div   id="377j5v51b"   class="phpmain1_2_top">
							<a href="javascript:void(0);" class="phpmain1_2_top_title">Related knowledge<img
									src="/static/imghw/index2_title2.png" alt="" /></a>
						</div>
						<div   id="377j5v51b"   class="phpgenera_Details_mainL4_info">

													<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796846916.html" title="PHP appelle AI Intelligent Voice Assistant Assistant PHP Interaction System Construction" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/503/042/175318512535508.jpeg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP appelle AI Intelligent Voice Assistant Assistant PHP Interaction System Construction" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796846916.html" title="PHP appelle AI Intelligent Voice Assistant Assistant PHP Interaction System Construction" class="phphistorical_Version2_mids_title">PHP appelle AI Intelligent Voice Assistant Assistant PHP Interaction System Construction</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 25, 2025 pm	 08:45 PM</span>
								<p class="Articlelist_txts_p">L'entrée vocale de l'utilisateur est capturée et envoyée au backend PHP via l'API MediaRecorder du JavaScript frontal; 2. PHP enregistre l'audio en tant que fichier temporaire et appelle STTAPI (tel que Google ou Baidu Voice Recognition) pour le convertir en texte; 3. PHP envoie le texte à un service d'IA (comme Openaigpt) pour obtenir une réponse intelligente; 4. PHP appelle ensuite TTSAPI (comme Baidu ou Google Voice Synthesis) pour convertir la réponse en fichier vocal; 5. PHP diffuse le fichier vocal vers l'avant pour jouer, terminant l'interaction. L'ensemble du processus est dominé par PHP pour assurer une connexion transparente entre toutes les liens.</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796846920.html" title="Comment utiliser PHP combiné avec l'IA pour obtenir la correction de texte de la syntaxe PHP détection et l'optimisation" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/503/042/175318452251625.jpeg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Comment utiliser PHP combiné avec l'IA pour obtenir la correction de texte de la syntaxe PHP détection et l'optimisation" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796846920.html" title="Comment utiliser PHP combiné avec l'IA pour obtenir la correction de texte de la syntaxe PHP détection et l'optimisation" class="phphistorical_Version2_mids_title">Comment utiliser PHP combiné avec l'IA pour obtenir la correction de texte de la syntaxe PHP détection et l'optimisation</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 25, 2025 pm	 08:57 PM</span>
								<p class="Articlelist_txts_p">Pour réaliser la correction d'erreur de texte et l'optimisation de la syntaxe avec l'IA, vous devez suivre les étapes suivantes: 1. Sélectionnez un modèle ou une API d'IA appropriée, tels que Baidu, Tencent API ou bibliothèque NLP open source; 2. Appelez l'API via Curl ou Guzzle de PHP et traitez les résultats de retour; 3. Afficher les informations de correction d'erreur dans l'application et permettre aux utilisateurs de choisir d'adopter l'adoption; 4. Utilisez PHP-L et PHP_CODESNIFFER pour la détection de syntaxe et l'optimisation du code; 5. Collectez en continu les commentaires et mettez à jour le modèle ou les règles pour améliorer l'effet. Lorsque vous choisissez AIAPI, concentrez-vous sur l'évaluation de la précision, de la vitesse de réponse, du prix et du support pour PHP. L'optimisation du code doit suivre les spécifications du PSR, utiliser le cache raisonnablement, éviter les requêtes circulaires, revoir le code régulièrement et utiliser x</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796847651.html" title="Python Seaborn JointPlot Exemple" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175348871135130.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Python Seaborn JointPlot Exemple" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796847651.html" title="Python Seaborn JointPlot Exemple" class="phphistorical_Version2_mids_title">Python Seaborn JointPlot Exemple</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 26, 2025 am	 08:11 AM</span>
								<p class="Articlelist_txts_p">Utilisez le plot conjoint de Seaborn pour visualiser rapidement la relation et la distribution entre deux variables; 2. Le tracé de diffusion de base est implémenté par sn.jointplot (data = pointes, x = "total_bill", y = "Tip", kind = "dispers"), le centre est un tracé de dispersion et l'histogramme est affiché sur les c?tés supérieur et inférieur et droit; 3. Ajouter des lignes de régression et des informations de densité à un kind = "reg" et combiner marginal_kws pour définir le style de tracé de bord; 4. Lorsque le volume de données est important, il est recommandé d'utiliser "Hex"</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796846879.html" title="PHP intégrée AI Technologie de l'informatique émotionnelle PHP Feedback User Retour Intelligent Analyse" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/503/042/175327212669514.png?x-oss-process=image/resize,m_fill,h_207,w_330" alt="PHP intégrée AI Technologie de l'informatique émotionnelle PHP Feedback User Retour Intelligent Analyse" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796846879.html" title="PHP intégrée AI Technologie de l'informatique émotionnelle PHP Feedback User Retour Intelligent Analyse" class="phphistorical_Version2_mids_title">PHP intégrée AI Technologie de l'informatique émotionnelle PHP Feedback User Retour Intelligent Analyse</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 25, 2025 pm	 06:54 PM</span>
								<p class="Articlelist_txts_p">Pour intégrer la technologie informatique des sentiments de l'IA dans les applications PHP, le noyau est d'utiliser les services cloud AIAPI (tels que Google, AWS et Azure) pour l'analyse des sentiments, envoyer du texte via les demandes HTTP et analyser les résultats JSON renvoyés et stocker les données émotionnelles dans la base de données, réalisant ainsi le traitement automatisé et les informations sur les données de la rétroaction des utilisateurs. Les étapes spécifiques incluent: 1. Sélectionnez une API d'analyse des sentiments d'IA appropriée, en considérant la précision, le co?t, le support linguistique et la complexité d'intégration; 2. Utilisez Guzzle ou Curl pour envoyer des demandes, stocker les scores de sentiment, les étiquettes et les informations d'intensité; 3. Construisez un tableau de bord visuel pour prendre en charge le tri prioritaire, l'analyse des tendances, la direction d'itération du produit et la segmentation de l'utilisateur; 4. Répondez aux défis techniques, tels que les restrictions d'appel API et les chiffres</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796847620.html" title="Python List to String Conversion Exemple" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175348803380357.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Python List to String Conversion Exemple" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796847620.html" title="Python List to String Conversion Exemple" class="phphistorical_Version2_mids_title">Python List to String Conversion Exemple</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 26, 2025 am	 08:00 AM</span>
								<p class="Articlelist_txts_p">Les listes de cha?nes peuvent être fusionnées avec la méthode join (), telles que '' .join (mots) pour obtenir "HelloworldFrompython"; 2. Les listes de nombres doivent être converties en cha?nes avec MAP (STR, nombres) ou [STR (x) Forxinnumbers] avant de rejoindre; 3. Toute liste de types peut être directement convertie en cha?nes avec des supports et des devis, adaptées au débogage; 4. Les formats personnalisés peuvent être implémentés par des expressions de générateur combinées avec join (), telles que '|' .join (f "[{item}]" ForIteminitems)</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796851468.html" title="Python Connexion à SQL Server PyoDBC Exemple" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175381521174852.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Python Connexion à SQL Server PyoDBC Exemple" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796851468.html" title="Python Connexion à SQL Server PyoDBC Exemple" class="phphistorical_Version2_mids_title">Python Connexion à SQL Server PyoDBC Exemple</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 30, 2025 am	 02:53 AM</span>
								<p class="Articlelist_txts_p">Installez PYODBC: utilisez la commande PiPInstallpyodbc pour installer la bibliothèque; 2. Connectez SQLServer: utilisez la cha?ne de connexion contenant le pilote, le serveur, la base de données, l'UID / PWD ou TrustEd_Connection via la méthode pyoDBC.Connect () et prendre en charge l'authentification SQL ou l'authentification Windows respectivement; 3. Vérifiez le pilote installé: exécutez pyodbc.Drivers () et filtrez le nom du pilote contenant ?SQLServer? pour vous assurer que le nom du pilote correct est utilisé tel que ?ODBCDriver17 pour SQLServer?; 4. Paramètres clés de la cha?ne de connexion</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796848426.html" title="Python pandas fondre l'exemple" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/431/639/175355571120355.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Python pandas fondre l'exemple" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796848426.html" title="Python pandas fondre l'exemple" class="phphistorical_Version2_mids_title">Python pandas fondre l'exemple</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 27, 2025 am	 02:48 AM</span>
								<p class="Articlelist_txts_p">pandas.melt () est utilisé pour convertir les données de format larges en format long. La réponse consiste à définir de nouveaux noms de colonne en spécifiant id_vars conserver la colonne d'identification, Value_Vars Sélectionnez la colonne à fondre, var_name et valeur_name, 1.id_vars = 'name' signifie que la colonne de nom reste inchangée, 2.Value_vars = [Math ',' English ',' Science '. du nom de colonne d'origine, 4.value_name = 'score' définit le nouveau nom de colonne de la valeur d'origine et génère enfin trois colonnes, notamment le nom, le sujet et le score.</p>
							</div>
														<div   id="377j5v51b"   class="phphistorical_Version2_mids">
								<a href="http://www.miracleart.cn/fr/faq/1796849397.html" title="Optimisation de Python pour les opérations liées à la mémoire" class="phphistorical_Version2_mids_img">
									<img onerror="this.onerror=''; this.src='/static/imghw/default1.png'"
										src="/static/imghw/default1.png" class="lazy"  data-src="https://img.php.cn/upload/article/001/253/068/175364417192026.jpg?x-oss-process=image/resize,m_fill,h_207,w_330" alt="Optimisation de Python pour les opérations liées à la mémoire" />
								</a>
								<a href="http://www.miracleart.cn/fr/faq/1796849397.html" title="Optimisation de Python pour les opérations liées à la mémoire" class="phphistorical_Version2_mids_title">Optimisation de Python pour les opérations liées à la mémoire</a>
								<span id="377j5v51b"    class="Articlelist_txts_time">Jul 28, 2025 am	 03:22 AM</span>
								<p class="Articlelist_txts_p">PythonCanBeoptimizedFormemory-Boundoperations AdreductoverHeadHroughGenerators, EfficientDatastructures et ManagingObjectliFetimes.first, useGeneratorsInSteadofListStoproceSlargedataseSeItematatime, EvitingLoadingEnteryToMeToMeMory.</p>
							</div>
													</div>

													<a href="http://www.miracleart.cn/fr/be/" class="phpgenera_Details_mainL4_botton">
								<span>See all articles</span>
								<img src="/static/imghw/down_right.png" alt="" />
							</a>
											</div>
				</div>
					</div>
	</main>
	<footer>
    <div   id="377j5v51b"   class="footer">
        <div   id="377j5v51b"   class="footertop">
            <img src="/static/imghw/logo.png" alt="">
            <p>Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!</p>
        </div>
        <div   id="377j5v51b"   class="footermid">
            <a href="http://www.miracleart.cn/fr/about/us.html">à propos de nous</a>
            <a href="http://www.miracleart.cn/fr/about/disclaimer.html">Clause de non-responsabilité</a>
            <a href="http://www.miracleart.cn/fr/update/article_0_1.html">Sitemap</a>
        </div>
        <div   id="377j5v51b"   class="footerbottom">
            <p>
                ? php.cn All rights reserved
            </p>
        </div>
    </div>
</footer>

<input type="hidden" id="verifycode" value="/captcha.html">




		<link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css?2' type='text/css' media='all' />
	
	
	
	
	

	
	






<footer>
<div class="friendship-link">
<p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p>
<a href="http://www.miracleart.cn/" title="国产av日韩一区二区三区精品">国产av日韩一区二区三区精品</a>

<div class="friend-links">


</div>
</div>

</footer>


<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</body><div id="wq8m9" class="pl_css_ganrao" style="display: none;"><acronym id="wq8m9"><sup id="wq8m9"><thead id="wq8m9"></thead></sup></acronym><form id="wq8m9"></form><ins id="wq8m9"><cite id="wq8m9"></cite></ins><ul id="wq8m9"></ul><center id="wq8m9"></center><samp id="wq8m9"></samp><strike id="wq8m9"><button id="wq8m9"></button></strike><b id="wq8m9"><i id="wq8m9"></i></b><strike id="wq8m9"></strike><dd id="wq8m9"></dd><input id="wq8m9"><xmp id="wq8m9"><input id="wq8m9"></input></xmp></input><wbr id="wq8m9"><u id="wq8m9"></u></wbr><dfn id="wq8m9"><listing id="wq8m9"></listing></dfn><td id="wq8m9"><kbd id="wq8m9"><th id="wq8m9"></th></kbd></td><dl id="wq8m9"><button id="wq8m9"><source id="wq8m9"><dfn id="wq8m9"></dfn></source></button></dl><u id="wq8m9"><code id="wq8m9"><ins id="wq8m9"></ins></code></u><small id="wq8m9"><style id="wq8m9"><progress id="wq8m9"></progress></style></small><sub id="wq8m9"><optgroup id="wq8m9"></optgroup></sub><address id="wq8m9"></address><delect id="wq8m9"><small id="wq8m9"><pre id="wq8m9"></pre></small></delect><div id="wq8m9"></div><meter id="wq8m9"></meter><tbody id="wq8m9"><label id="wq8m9"><sub id="wq8m9"></sub></label></tbody><li id="wq8m9"><samp id="wq8m9"></samp></li><code id="wq8m9"></code><option id="wq8m9"><wbr id="wq8m9"><u id="wq8m9"><center id="wq8m9"></center></u></wbr></option><menu id="wq8m9"></menu><meter id="wq8m9"></meter><strong id="wq8m9"><div id="wq8m9"></div></strong><tr id="wq8m9"></tr><tr id="wq8m9"><noframes id="wq8m9"><pre id="wq8m9"></pre></noframes></tr><nav id="wq8m9"><thead id="wq8m9"><input id="wq8m9"><del id="wq8m9"></del></input></thead></nav><tr id="wq8m9"><strike id="wq8m9"></strike></tr><rt id="wq8m9"></rt><kbd id="wq8m9"><strong id="wq8m9"><mark id="wq8m9"></mark></strong></kbd><strong id="wq8m9"></strong><abbr id="wq8m9"></abbr><dd id="wq8m9"></dd><delect id="wq8m9"></delect><small id="wq8m9"><tfoot id="wq8m9"></tfoot></small><ul id="wq8m9"><legend id="wq8m9"><ul id="wq8m9"><dl id="wq8m9"></dl></ul></legend></ul><sup id="wq8m9"><strong id="wq8m9"></strong></sup><ul id="wq8m9"><strike id="wq8m9"></strike></ul><em id="wq8m9"><pre id="wq8m9"></pre></em><b id="wq8m9"></b><pre id="wq8m9"><ol id="wq8m9"></ol></pre><track id="wq8m9"></track><strike id="wq8m9"></strike><dl id="wq8m9"></dl><th id="wq8m9"></th><tfoot id="wq8m9"><track id="wq8m9"><sup id="wq8m9"></sup></track></tfoot><wbr id="wq8m9"></wbr><td id="wq8m9"></td><pre id="wq8m9"></pre><noframes id="wq8m9"></noframes><kbd id="wq8m9"><strong id="wq8m9"><mark id="wq8m9"></mark></strong></kbd><sup id="wq8m9"></sup><sup id="wq8m9"><thead id="wq8m9"><input id="wq8m9"><del id="wq8m9"></del></input></thead></sup><strong id="wq8m9"></strong><dfn id="wq8m9"><listing id="wq8m9"></listing></dfn><dl id="wq8m9"><sup id="wq8m9"><input id="wq8m9"></input></sup></dl><style id="wq8m9"><progress id="wq8m9"><cite id="wq8m9"></cite></progress></style><li id="wq8m9"><legend id="wq8m9"></legend></li><cite id="wq8m9"></cite><delect id="wq8m9"><small id="wq8m9"><ins id="wq8m9"></ins></small></delect><kbd id="wq8m9"><strong id="wq8m9"><mark id="wq8m9"></mark></strong></kbd><pre id="wq8m9"></pre><dd id="wq8m9"></dd><cite id="wq8m9"><pre id="wq8m9"><nav id="wq8m9"><thead id="wq8m9"></thead></nav></pre></cite><label id="wq8m9"></label><li id="wq8m9"><dl id="wq8m9"><th id="wq8m9"></th></dl></li><sup id="wq8m9"><strong id="wq8m9"><address id="wq8m9"><table id="wq8m9"></table></address></strong></sup><dl id="wq8m9"><sup id="wq8m9"><input id="wq8m9"></input></sup></dl><dl id="wq8m9"></dl><pre id="wq8m9"></pre><td id="wq8m9"><kbd id="wq8m9"><td id="wq8m9"></td></kbd></td><tbody id="wq8m9"></tbody><optgroup id="wq8m9"><td id="wq8m9"><form id="wq8m9"></form></td></optgroup><ul id="wq8m9"></ul><fieldset id="wq8m9"><center id="wq8m9"><th id="wq8m9"></th></center></fieldset><optgroup id="wq8m9"><legend id="wq8m9"><li id="wq8m9"><meter id="wq8m9"></meter></li></legend></optgroup><sup id="wq8m9"></sup><fieldset id="wq8m9"></fieldset><option id="wq8m9"><object id="wq8m9"><tt id="wq8m9"><rt id="wq8m9"></rt></tt></object></option><optgroup id="wq8m9"><xmp id="wq8m9"><bdo id="wq8m9"></bdo></xmp></optgroup><abbr id="wq8m9"></abbr><strike id="wq8m9"><video id="wq8m9"><strike id="wq8m9"><abbr id="wq8m9"></abbr></strike></video></strike><dd id="wq8m9"><strong id="wq8m9"></strong></dd><form id="wq8m9"></form><optgroup id="wq8m9"><xmp id="wq8m9"><bdo id="wq8m9"></bdo></xmp></optgroup><sup id="wq8m9"></sup><input id="wq8m9"></input><ins id="wq8m9"><dfn id="wq8m9"></dfn></ins><table id="wq8m9"></table><address id="wq8m9"><input id="wq8m9"><xmp id="wq8m9"><s id="wq8m9"></s></xmp></input></address><code id="wq8m9"><tr id="wq8m9"><dfn id="wq8m9"></dfn></tr></code></div>

</html>