<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                我們可以調用`soup.find(css選擇器)`、`soup.find_all(css選擇器)`,`soup.select(css選擇器)`來根據CSS選擇器獲取指定的元素。 ```python # 標簽選擇器 soup.select('img') # 類名選擇器 soup.select('.sister') # id選擇器 soup.select('#sister') # 組合選擇器 soup.select('img #sister') # 屬性選擇器 soup.select('img[src="https://tva1.sinaimg.cn/bmiddle/0080xEK2gy1gntyyf21btj30u0140dje.jpg"]' ``` 使用案例: ```python """ @Date 2021/3/18 """ from bs4 import BeautifulSoup html_doc = """ <table class="tablelist" cellspacing="0" cellpadding="0"> <tbody> <tr class="h"> <td class="1" width="374">職位名稱</td> <td>職位類別</td> <td>人數</td> <td>地點</td> <td>發布時間</td> </tr> <tr class="even"> <td class="l"><a href="https://www.baidu.com">區塊鏈高級研發工程師</a></td> <td class="l">技術類</td> <td class="l">1</td> <td class="l">深圳</td> <td class="l">2018-11-25</td> </tr> <tr class="even"> <td><a href="https://www.qq.com">金融云高級后臺開發</a></td> <td>技術類</td> <td>2</td> <td>深圳</td> <td>2018-11-24</td> </tr> <tr> <td><a href="https://www.juran.com">高級研發工程師</a></td> <td>技術類</td> <td>2</td> <td>深圳</td> <td>2018-11-24</td> </tr> <tr> <td><a href="https://www.python.com">高級圖像算法工程師</a></td> <td>技術類</td> <td>2</td> <td>深圳</td> <td>2018-11-24</td> </tr> <tr> <td><a href="https://www.lg.com" id="test" class="test">高級業務運維工程師</a></td> <td>技術類</td> <td>2</td> <td>深圳</td> <td>2018-11-24</td> </tr> </tbody> </table> """ soup = BeautifulSoup(html_doc, 'lxml') ############ find ############ # 1. 獲取首個匹配的tr元素 # tr = soup.find('tr') # 2. 獲取該標簽下的所有子元素(str) # print(tr.contents) # 3. 返回該元素的所有直接子節點的列表 # print(list(tr.children)) # 4. 返回該元素的直接父節點 # tdf = soup.find('td').parent # print(tdf) ########### find_all ########### # 1. 返回所有tr標簽的列表 # trs = soup.find_all('tr') # print(trs) # for tr in trs: # print(tr) # print(type(tr)) # 返回的不是字符串,而是<class 'bs4.element.Tag'> # print("="*30) # 2. 獲取第2個tr標簽 # tr = soup.find_all('tr', limit=2)[1] # # print(tr) # 3.獲取所有class等于even的tr標簽 # trs = soup.find_all('tr', class_='even') # trs = soup.find_all('tr', attrs={"class": 'even'}) # for tr in trs: # print(tr) # print("="*30) # 4. 將所有id等于test,class也等于test的a標簽提取出來 # alist = soup.find_all('a', attrs={"id": "test", "class": "test"}) # alist = soup.find_all('a', id="test", class_="test") # print(alist) # 5. 獲取所有的a標簽 # hrefs = soup.find_all('a') # for a in hrefs: # print(a) # (1)獲取a標簽的href屬性 # href = a['hrefs'] # 如果沒有取到返回None # (2)獲取a標簽的href屬性 # href = a.get('hrefs') # print(href) # (3)通過attrs屬性的方式 # href = a.attrs['hrefs'] # print(href) # 6. 獲取所有的職位信息(純文本) # trs = soup.find_all('tr')[1:] # for tr in trs: # print(tr) # tds = tr.find_all('td') # print(tds) # title = tds[0] # print(title.string) # 獲取tr標簽的所有文本 # infos = list(tr.strings) # print(infos) # 可以去除空格取純文本 # infos = list(tr.stripped_strings) # print(infos[0]) ############# select ############## # 1. 獲取所有tr標簽 # trs = soup.select('tr') # print(trs) # 2. 獲取第2個tr標簽 # tr = soup.select('tr')[1] # print(tr) # 3. 獲取所有class等于even的tr標簽 # tr = soup.select('tr.even') # print(tr) # 4. 獲取所有的a標簽的href屬性 # alist = soup.select('a') # for a in alist: # href = a.get('href') # print(href) # 5. 獲取所有的tr標簽 # trs = soup.select('tr') # for tr in trs: # # 5. 獲取所有的職位信息(純文本) # infos = list(tr.stripped_strings) # print(infos) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看