无法用python打印数据

2024-09-30 16:39:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是从单个站点的多个链接中提取数据,但我面临的问题是在3个链接后打印空数组。它打印从1到2的结果,然后在第二个链接后打印空数组,然后再次打印非空数组。我的代码也处于运行状态。它不会在第72超链接后停止。 这样,使用空数组时,它将转到700

import requests
from bs4 import BeautifulSoup
import pandas as pd
import time
suit =[]
url=["https://sehat.com.pk/products/After-Biotic-Cap-30%27s.html",
"https://sehat.com.pk/products/Amybact-Powder-Sachets-10%27s.html",
"https://sehat.com.pk/products/Bactocell-Probiotic-Sachet-10%27s.html",
"https://sehat.com.pk/products/BC%252d2Bio-Oral-Susp-2billion%7B47%7D5ml-",
"https://sehat.com.pk/products/Bio%252dKult-Candea-Cap-60%27s.html",
"https://sehat.com.pk/products/Bio%252dKult-Infantis-Sachet-16%27s.html",
"https://sehat.com.pk/products/Bio%252dKult-Multi%252dStrain-Cap-30%27s.h",
"https://sehat.com.pk/products/DiaResQ-Sachet-3%27s.html",
"https://sehat.com.pk/products/Doctile-powder-Sachet-3g-30%27s.html",
"https://sehat.com.pk/products/Enterogermina-2-Billion%7B47%7D5ml-Oral-Su",
"https://sehat.com.pk/products/Enterogermina-4-Billion%7B47%7D5ml-Oral-Su",
"https://sehat.com.pk/products/Enterogermina-Oral-Susp-10%27s.html",
"https://sehat.com.pk/products/Ezegut-Probiotic-Drops-5ml.html",
"https://sehat.com.pk/products/Gravinate-Liq-12.5mg%7B47%7D4ml-60ml.html",
"https://sehat.com.pk/products/Orsiflor%252dZ-Sachet-10%27s.html",
"https://sehat.com.pk/products/Prepro%252dgg-Sachets-10%27s.html",
"https://sehat.com.pk/products/Proflor-Oral-Susp-8Ampx5ml.html",
"https://sehat.com.pk/products/Prohale-Chewable-Tab-2-Billion-CFU-30%27s.",
"https://sehat.com.pk/products/S-%281%252d4%29--%28Diarrhea-Food-Poisonin",
"https://sehat.com.pk/products/Enterogermina-Oral-Susp-20Ampx5ml.html",
"https://sehat.com.pk/products/Enflor-Cap-10%27s.html",
"https://sehat.com.pk/products/Enflor-Powder-Sachet-10%27s.html",
"https://sehat.com.pk/products/Ecotec-Cap-180mg-10%27s.html",
"https://sehat.com.pk/products/Ecotec-Powder-Sachet-10%27s.html",
"https://sehat.com.pk/products/Gravinate-Liq-12.5mg%7B47%7D4ml-120ml.html",
"https://sehat.com.pk/products/Gravinate-Tab-50mg-10%27s.html",
"https://sehat.com.pk/products/Gravinate-Tab-50mg-100%27s.html",
"https://sehat.com.pk/products/Gutcare-Cap-420mg%7B47%7D500mg-12%27s.html",
"https://sehat.com.pk/products/Gutcare-Powder-Sachets-10%27s.html",
"https://sehat.com.pk/products/Uflora-Cap-10%27s.html",
"https://sehat.com.pk/products/Probact-lozenges-10%27s.html",
"https://sehat.com.pk/products/Smecta-Powder-Sachet-1%27s.html",
"https://sehat.com.pk/products/Smecta-Powder-Sachet-30%27s.html",
"https://sehat.com.pk/products/Actiflor-Powder-Sachet-250mg-10%27s.html",
"https://sehat.com.pk/products/Pro%252dBerry-Probiotics-Cap-14%27s.html",
"https://sehat.com.pk/products/Pro%252dZ-Probiotic-Cap-14%27s.html",
"https://sehat.com.pk/products/Gutshine-Powder-Sachet-10%27s.html",
"https://sehat.com.pk/products/Newflora-Cap-25%27s.html",
"https://sehat.com.pk/products/Diosecta-Powder-Sachet-3gm-30%27s.html",
"https://sehat.com.pk/products/Neo-Q%252dpalgite-Susp-120ml.html",
"https://sehat.com.pk/products/Neo-Q%252dplex-Susp-120ml.html",
"https://sehat.com.pk/products/Neo-Q%252dplex-Z--Susp-120ml.html",
"https://sehat.com.pk/products/Olomine-DS-Eye-Drops-0.1%25-5ml.html",
"https://sehat.com.pk/products/I%252dMenate-Syp-12.5mg%7B47%7D5ml-60ml.ht",
"https://sehat.com.pk/products/I%252dMenate-Tab-50mg-10x10%27s.html",
"https://sehat.com.pk/products/I%252dMenate-Tab-50mg-10x25%27s.html",
"https://sehat.com.pk/products/UNETOX%252dT-Tab-500mg-100%27s.html",
"https://sehat.com.pk/products/UNETOX%252dT-Tab-500mg-500%27s.html",
"https://sehat.com.pk/products/DAVISSALTS-Sachet-40%27s.html",
"https://sehat.com.pk/products/Dymin-Syp-12.5mg%7B47%7D4ml-60ml.html",
"https://sehat.com.pk/products/Dymin-Tab-50mg-100%27s.html",
"https://sehat.com.pk/products/Ezegut-Drops-10ml.html",
"https://sehat.com.pk/products/Libs-Cap-20%27s.html",
"https://sehat.com.pk/products/KAOTIN-Susp-120ml.html",
"https://sehat.com.pk/products/KAOTIN-Susp-450ml.html",
"https://sehat.com.pk/products/KAOTIN-Susp-60ml.html",
"https://sehat.com.pk/products/PAEDITROL-Sachet-27.9gm.html",
"https://sehat.com.pk/products/Floraid-Cap-250mg-10%27s.html",
"https://sehat.com.pk/products/Floraid-Powder-Sachet-250mg-10%27s.html",
"https://sehat.com.pk/products/BABY%252dS-Sachet-1%27s.html",
"https://sehat.com.pk/products/BANTOX-Tab-500mg-100%27s.html",
"https://sehat.com.pk/products/BEETOX-Tab-500mg-100%27s.html",
"https://sehat.com.pk/products/Bifilor-Sachet-10%27s.html",
"https://sehat.com.pk/products/C%252dNate-Inj-50mg-25Ampx1ml.html",
"https://sehat.com.pk/products/DIROSAL-Sachet-28.4gm.html",
"https://sehat.com.pk/products/Enfamil--AR-Powder-400g.html",
"https://sehat.com.pk/products/Enfamil-O%252dLac-Powder-400g.html",
"https://sehat.com.pk/products/Entox%252dP-Tab-500mg-100%27s.html",
"https://sehat.com.pk/products/KAOMAGMA-Susp-90ml.html",
"https://sehat.com.pk/products/KEMYPUGITE-Susp1.0mg%7B47%7D10ml-60ml.html",
"https://sehat.com.pk/products/KEMYTRAL-Powder-1%27s.html",
"https://sehat.com.pk/products/KEYTIN-Susp-60ml.html",
"https://sehat.com.pk/products/NEPECTOL-Syp-60ml.html",
"https://sehat.com.pk/products/ORALYTE-Powder-Sachets-20%27s.html",
"https://sehat.com.pk/products/SEVIDOXINE-Tab-100%27s.html",
"https://sehat.com.pk/products/After-Biotic-Cap-30%27s.html",
"https://sehat.com.pk/products/Amybact-Powder-Sachets-10%27s.html",
"https://sehat.com.pk/products/Bactocell-Probiotic-Sachet-10%27s.html",
"https://sehat.com.pk/products/BC%252d2Bio-Oral-Susp-2billion%7B47%7D5ml-",
"https://sehat.com.pk/products/Bio%252dKult-Candea-Cap-60%27s.html",
"https://sehat.com.pk/products/Bio%252dKult-Infantis-Sachet-16%27s.html",
"https://sehat.com.pk/products/Bio%252dKult-Multi%252dStrain-Cap-30%27s.h",
"https://sehat.com.pk/products/DiaResQ-Sachet-3%27s.html",
"https://sehat.com.pk/products/Doctile-powder-Sachet-3g-30%27s.html",
"https://sehat.com.pk/products/Enterogermina-2-Billion%7B47%7D5ml-Oral-Su",
"https://sehat.com.pk/products/Enterogermina-4-Billion%7B47%7D5ml-Oral-Su",
"https://sehat.com.pk/products/Enterogermina-Oral-Susp-10%27s.html",
"https://sehat.com.pk/products/Ezegut-Probiotic-Drops-5ml.html",
"https://sehat.com.pk/products/Gravinate-Liq-12.5mg%7B47%7D4ml-60ml.html",
"https://sehat.com.pk/products/Orsiflor%252dZ-Sachet-10%27s.htm",
"https://sehat.com.pk/products/Prepro%252dgg-Sachets-10%27s.htm",
"https://sehat.com.pk/products/Proflor-Oral-Susp-8Ampx5ml.htm",
"https://sehat.com.pk/products/Prohale-Chewable-Tab-2-Billion-CFU-30%27s",
"https://sehat.com.pk/products/S-%281%252d4%29--%28Diarrhea-Food-Poisoni",
"https://sehat.com.pk/products/Enterogermina-Oral-Susp-20Ampx5ml.htm",
"https://sehat.com.pk/products/Enflor-Cap-10%27s.htm",
"https://sehat.com.pk/products/Enflor-Powder-Sachet-10%27s.htm",
"https://sehat.com.pk/products/Ecotec-Cap-180mg-10%27s.htm",
"https://sehat.com.pk/products/Ecotec-Powder-Sachet-10%27s.htm",
"https://sehat.com.pk/products/Gravinate-Liq-12.5mg%7B47%7D4ml-120ml.htm",
"https://sehat.com.pk/products/Gravinate-Tab-50mg-10%27s.htm",
"https://sehat.com.pk/products/Gravinate-Tab-50mg-100%27s.htm",
"https://sehat.com.pk/products/Gutcare-Cap-420mg%7B47%7D500mg-12%27s.htm",
"https://sehat.com.pk/products/Gutcare-Powder-Sachets-10%27s.htm",
"https://sehat.com.pk/products/Uflora-Cap-10%27s.htm",
"https://sehat.com.pk/products/Probact-lozenges-10%27s.htm",
"https://sehat.com.pk/products/Smecta-Powder-Sachet-1%27s.htm",
"https://sehat.com.pk/products/Smecta-Powder-Sachet-30%27s.htm",
"https://sehat.com.pk/products/Actiflor-Powder-Sachet-250mg-10%27s.htm",
"https://sehat.com.pk/products/Pro%252dBerry-Probiotics-Cap-14%27s.htm",
"https://sehat.com.pk/products/Pro%252dZ-Probiotic-Cap-14%27s.htm",
"https://sehat.com.pk/products/Gutshine-Powder-Sachet-10%27s.htm",
"https://sehat.com.pk/products/Newflora-Cap-25%27s.htm",
"https://sehat.com.pk/products/Diosecta-Powder-Sachet-3gm-30%27s.htm",
"https://sehat.com.pk/products/Neo-Q%252dpalgite-Susp-120ml.htm",
"https://sehat.com.pk/products/Neo-Q%252dplex-Susp-120ml.htm",
"https://sehat.com.pk/products/Neo-Q%252dplex-Z--Susp-120ml.htm",
"https://sehat.com.pk/products/Olomine-DS-Eye-Drops-0.1%25-5ml.htm",
"https://sehat.com.pk/products/I%252dMenate-Syp-12.5mg%7B47%7D5ml-60ml.h",
"https://sehat.com.pk/products/I%252dMenate-Tab-50mg-10x10%27s.htm",
"https://sehat.com.pk/products/I%252dMenate-Tab-50mg-10x25%27s.htm",
"https://sehat.com.pk/products/UNETOX%252dT-Tab-500mg-100%27s.htm",
"https://sehat.com.pk/products/UNETOX%252dT-Tab-500mg-500%27s.htm",
"https://sehat.com.pk/products/DAVISSALTS-Sachet-40%27s.htm",
"https://sehat.com.pk/products/Dymin-Syp-12.5mg%7B47%7D4ml-60ml.htm",
"https://sehat.com.pk/products/Dymin-Tab-50mg-100%27s.htm",
"https://sehat.com.pk/products/Ezegut-Drops-10ml.htm",
"https://sehat.com.pk/products/Libs-Cap-20%27s.htm",
"https://sehat.com.pk/products/KAOTIN-Susp-120ml.htm",
"https://sehat.com.pk/products/KAOTIN-Susp-450ml.htm",
"https://sehat.com.pk/products/KAOTIN-Susp-60ml.htm",
"https://sehat.com.pk/products/PAEDITROL-Sachet-27.9gm.htm",
"https://sehat.com.pk/products/Floraid-Cap-250mg-10%27s.htm",
"https://sehat.com.pk/products/Floraid-Powder-Sachet-250mg-10%27s.htm",
"https://sehat.com.pk/products/BABY%252dS-Sachet-1%27s.htm",
"https://sehat.com.pk/products/BANTOX-Tab-500mg-100%27s.htm",
"https://sehat.com.pk/products/BEETOX-Tab-500mg-100%27s.htm",
"https://sehat.com.pk/products/Bifilor-Sachet-10%27s.htm",
"https://sehat.com.pk/products/C%252dNate-Inj-50mg-25Ampx1ml.htm",
"https://sehat.com.pk/products/DIROSAL-Sachet-28.4gm.htm",
"https://sehat.com.pk/products/Enfamil--AR-Powder-400g.htm",
"https://sehat.com.pk/products/Enfamil-O%252dLac-Powder-400g.htm",
"https://sehat.com.pk/products/Entox%252dP-Tab-500mg-100%27s.htm",
"https://sehat.com.pk/products/KAOMAGMA-Susp-90ml.htm",
"https://sehat.com.pk/products/KEMYPUGITE-Susp1.0mg%7B47%7D10ml-60ml.htm",
"https://sehat.com.pk/products/KEMYTRAL-Powder-1%27s.htm",
"https://sehat.com.pk/products/KEYTIN-Susp-60ml.htm",
"https://sehat.com.pk/products/NEPECTOL-Syp-60ml.htm",
"https://sehat.com.pk/products/ORALYTE-Powder-Sachets-20%27s.htm",
"https://sehat.com.pk/products/SEVIDOXINE-Tab-100%27s.html"]
count=0
for endpoint in url:
    print(count)
    count+=1
    r = requests.get(endpoint)
    time.sleep(6)
    soup = BeautifulSoup(r.content, 'html.parser')
    time.sleep(1)
    content = soup.find_all('div', class_ = 'Block Moveable Panel PrimaryProductDetails')
    print(content)

Tags: httpscomhtmltabproductscappkhtm
1条回答
网友
1楼 · 发布于 2024-09-30 16:39:30

有时,BeautifulSoup无法始终找到您要查找的内容,因此它返回一个空数组,因为soup.find_all返回一个包含所有结果的数组

这可能是因为它请求的页面没有您正在寻找的产品

相关问题 更多 >