第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

BeautifulSoup.find_all() 不打印所有結(jié)果

BeautifulSoup.find_all() 不打印所有結(jié)果

慕田峪7331174 2022-10-25 15:57:45
我正在做一個網(wǎng)頁抓取項目,我想抓取特定表格中的所有元素。這是我要從中抓取數(shù)據(jù)的網(wǎng)站。到目前為止,這是我的代碼url = 'https://www.alkemlabs.com/rx-products.php'response = requests.get(url)soup = BeautifulSoup(response.text, 'html.parser')for tr in soup.find_all('tr'):    tds = tr.find_all('td')    ths = tr.find_all('th')    try:        print(f'Brand: {ths[0].text}, Therapy Area - : {tds[0].text}, SKU - : {tds[1].text}, Strength: {tds[2].text}')    except: continue代碼的輸出如下Brand: XONE SB, Therapy Area - : Anti-infective, SKU - : XONE SB 250MG INJECTION (VIALS), Strength: CEFTRIAXONE 250MG + SULBACTAM 125MGBrand: XONE SB, Therapy Area - : Anti-infective, SKU - : XONE SB 500 MG INJECTION (VIALS), Strength: CEFTRIAXONE 500MG + SULBACTAM 250MGBrand: Acuflam, Therapy Area - : PAIN & ANTI-INFLAMMMATORY, SKU - : ACUFLAM MR TABLETS (10'S), Strength: Acelofenac 100 mg + Paracetamol 325 mg + Chlorzoxazone 250 mg該代碼僅從三個表中打印出三行,而表中還有更多行。為什么會這樣?
查看完整描述

2 回答

?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

import requests

from bs4 import BeautifulSoup



def main(url):

    r = requests.get(url)

    soup = BeautifulSoup(r.content, 'html.parser')

    target = soup.findAll("th", scope="row")

    for tar in target:

        print("Brand: {:<15}, Therapy Area - : {:<50}, SKU - : {:<30}, Strength: {}".format(

            tar.text, *[item.text for item in tar.find_all_next("td")[:3]]))



main("https://www.alkemlabs.com/rx-products.php")

輸出樣本:


Brand: A TO Z         , Therapy Area - : Vitamins / Minerals / Nutrients                   , SKU - : NEW A TO Z GOLD CAPSULES (15'S), Strength: ASCORBIC ACID + BENFOTIAMINE + BETACAROTENE + DOCONEXENT + FOLIC ACID + ICOSAPENT + PROCYANIDIN + PYRIDOXINE + THIOCTIC ACID + VITAMIN E

Brand: XONE SB        , Therapy Area - : Anti-infective                                    , SKU - : XONE SB 250MG INJECTION (VIALS), Strength: CEFTRIAXONE 250MG + SULBACTAM 125MG

Brand: XONE SB        , Therapy Area - : Anti-infective                                    , SKU - : XONE SB 500 MG INJECTION (VIALS), Strength: CEFTRIAXONE 500MG + SULBACTAM 250MG

Brand: XONE SB        , Therapy Area - : Anti-infective                                    , SKU - : XONE SB 1GM INJECTION (VIALS) , Strength: CEFTRIAXONE 1000MG + SULBACTAM 500MG

Brand: COLPEP         , Therapy Area - : Gastro Intestinal                                 , SKU - : COLPEP SUSPENSION (30ML)      , Strength: DICYCLOMINE HCl 10MG + ACTIVATED DIMETHICONE 40MG / 5ML SUSP

Brand: COLPEP         , Therapy Area - : Gastro Intestinal                                 , SKU - : COLPEP DROPS (15ML)           , Strength: ACTIVATED DIMETHICONE 40MG + DILL OIL 0.005ML + FENNEL OIL 0.0007MG / ML SYRUP

Brand: COLPEP         , Therapy Area - : Gastro Intestinal                                 , SKU - : COLPEP SPAS TABLETS (10'S)    , Strength: Aceclofenac 100mg + Drotravarine 80mg Tablets

Brand: DIGIPEN        , Therapy Area - : Gastro Intestinal                                 , SKU - : DIGIPEN JUNIOR SYRUP (60ML)   , Strength: Alpha Amylase I.P. 100Mg (Bacterial 1:800) + Papain I.P. 50 Mg

Brand: DIGIPEN        , Therapy Area - : Gastro Intestinal                                 , SKU - : DIGIPEN DROPS (15ML)          , Strength: Alpha Amylase I.P. 20mg (Bacterial 1:800) + Papain I.P. 10mg + Dill oil B.P. 2mg + Anise oil B.P. 2mg + Caraway oil B.P. 2mg

Brand: DIGIPEN        , Therapy Area - : Gastro Intestinal                                 , SKU - : DIGIPEN TABLETS (10'S)        , Strength: Protease 3600 HUT + Amylase 1200 SKB + Hemicellulase 600 XU +á Lipase 450 FIP + Lactalase 250 ALU + Alpha Galactosidase 50 Gal U Chewable Tablets

Brand: HEMFER         , Therapy Area - : Gynaec.                                           , SKU - : HEMFER CAPSULES (NEW)(30'S)   , Strength: FERROUS GLYCINE SULPHATE 50MG (EQUI. IRON) + FOLIC ACID 0.5MG + CYANOCOBALAMINE 7.5MCG + ZINC SULPHATE 5MG (EQUI. ZINC)

Brand: HEMFER         , Therapy Area - : Gynaec.                                           , SKU - : HEMFER INJECTION (5ML)        , Strength: FERRIC HYDROXIDE WITH SUCROSE 100MG (EQUI. IRON)

Brand: HEMFER         , Therapy Area - : Gynaec.                                           , SKU - : HEMFER KID SYRUP (60ML)       , Strength: FERROUS GLYCINE SULPHATE 25MG (IRON EQUI.) + FOLIC ACID 0.25MG + CYANOCOBALAMINE 3.75MCG + ZINC SULPHATE MONOHYDRATEá3.5MG (ZINC EQUI.) / 5 ML DROPS

Brand: HEMFER         , Therapy Area - : Gynaec.                                           , SKU - : HEMFER SYRUP (225ML)          , Strength: FERROUS GLYCINE SULPHATE 50MG (EQUI. IRON) + FOLIC ACID 0.5MG + CYANOCOBALAMINE 7.5MCG + ZINC SULPHATE 2.5MG (EQUI. ZINC) + D-BIOTIN 100MCG / 15ML

Brand: HEMFER         , Therapy Area - : Gynaec.                                           , SKU - : HEMFER DROPS (15ML)           , Strength: FERROUS GLYCINE SULPHATE 10MG (IRON EQUI.) + FOLIC ACID 100MCG + CYANOCOBALAMINE 1.5MCG / ML DROPS

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO 4.5 GM INJECTION (VIAL) , Strength: PIPERACILLIN 4G + TAZOBACTAM 500MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO 4.5GM INJECTION (VIAL)  , Strength: PIPERACILLIN 4G + TAZOBACTAM 500MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO 4.5GM INJECTION (HOSPITAL SUPPLY), Strength: PIPERACILLIN 4G + TAZOBACTAM 500MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO-1.125 INJECTION (VIAL)  , Strength: PIPERACILLIN 1G + TAZOBACTAM 125MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO 1.125GM INJECTION (VIAL), Strength: PIPERACILLIN 1G + TAZOBACTAM 125MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective                                    , SKU - : PIPZO 2.25 GM INJECTION (VIAL), Strength: PIPERACILLIN 2G + TAZOBACTAM 250MG INJ

Brand: PIPZO          , Therapy Area - : Anti-infective           


查看完整回答
反對 回復 2022-10-25
?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊

這是因為 HTML 的結(jié)構(gòu)與您在代碼中所期望的不同。由于這個原因,許多調(diào)用將被阻塞

print(tr) 在 for 循環(huán)中,您將了解每一行的結(jié)構(gòu)。然后你可以根據(jù)要求修改你的代碼


查看完整回答
反對 回復 2022-10-25
  • 2 回答
  • 0 關(guān)注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號