如何使用 Python 找到 BeautifulSoup 的下一个标签/元素?

如何找到下一个标签/元素?


首先,我搜索我想要的 HTML 页面部分


soup_title = soup.find('a', id=title_idnext).getText()

这回来了


"7 DRUG INTERACTIONS "


<a class="" href="#" id="anch_dj_dj-dj_9">7 DRUG INTERACTIONS </a>

到目前为止一切都很好。


接下来,我使用


soup.find_next_element('div', class_='Section toggle-content closed long-content')

从中查找一些文本段落


<div class="Section toggle-content closed long-content" data-sectioncode="34073-7" style="">

<p>paragraph1...</p>

<p>paragraph2...</p>

<p>paragraph3...</p>

</div>

但我得到的只是空的,空字符串


我尝试过 soup.find_next_sibling/s、soup.findNextSibling/s - 没有乐趣


实际的URL是https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=00a574e0-bd03-deea-9f85-b108f78982ba



繁华开满天机
浏览 120回答 2
2回答

慕田峪4524236

既然您已经确定了需要用来find_next()获取 div 标签的锚标记。res=requests.get("https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=00a574e0-bd03-deea-9f85-b108f78982ba").textsoup=BeautifulSoup(res,'html.parser')soup_title = soup.find('a', id='anch_dj_dj-dj_9')print(soup_title.getText())print(soup_title.find_next('div', class_='Section toggle-content closed long-content').text)&nbsp;输出:7 DRUG INTERACTIONS&nbsp;Tables 2 and 3 include drugs with clinically important drug interactions and interaction with diagnostics when administered concomitantly with lansoprazole delayed release capsules and instructions for preventing or managing them.Consult the labeling of concomitantly used drugs to obtain further information about interactions with PPIs.&nbsp;Table 2. Clinically Relevant Interactions Affecting Drugs Co-Administered with Lansoprazole Delayed Release Capsules and Interactions with DiagnosticsAntiretrovirals&nbsp;Clinical Impact: The effect of PPIs on antiretroviral drugs is variable. The clinical importance and the mechanisms behind these interactions are not always known.&nbsp;&nbsp;Decreased exposure of some antiretroviral drugs (e.g., rilpivirine, atazanavir, and nelfinavir) when used concomitantly with lansoprazole may reduce antiviral effect and promote the development of drug resistance.Increased exposure of other antiretroviral drugs (e.g., saquinavir) when used concomitantly with lansoprazole may increase toxicity of the antiretroviral drugs.There are other antiretroviral drugs which do not result in clinically relevant interactions with lansoprazole.Intervention:&nbsp; Rilpivirine-containing products: Concomitant use with Lansoprazole delayed release capsules is contraindicated [see Contraindications (4)]. See prescribing information.&nbsp;&nbsp;Atazanavir: See prescribing information for atazanavir for dosing information.&nbsp;&nbsp;Nelfinavir: Avoid concomitant use with Lansoprazole. See prescribing information for nelfinavir.&nbsp;&nbsp;Saquinavir: See the prescribing information for saquinavir and monitor for potential saquinavir toxicities.&nbsp;&nbsp;Other antiretrovirals: See prescribing information.&nbsp;Warfarin&nbsp;Clinical Impact: Increased INR and prothrombin time in patients receiving PPIs and warfarin concomitantly. Increases in INR and prothrombin time may lead to abnormal bleeding and even death.&nbsp;Intervention:&nbsp; Monitor INR and prothrombin time. Dose adjustment of warfarin may be needed to maintain target INR range. See prescribing information for warfarin.&nbsp;MethotrexateClinical Impact:&nbsp; Concomitant use of PPIs with methotrexate (primarily at high dose) may elevate and prolong serum concentrations of methotrexate and/or its metabolite hydroxymethotrexate, possibly leading to methotrexate toxicities. No formal drug interaction studies of high-dose methotrexate with PPIs have been conducted [see Warnings and Precautions (5.8)].&nbsp;Intervention:&nbsp; A temporary withdrawal of Lansoprazole may be considered in some patients receiving high-dose methotrexate.&nbsp;Digoxin&nbsp;Clinical Impact: Potential for increased exposure of digoxin&nbsp;Intervention:&nbsp; Monitor digoxin concentrations. Dose adjustment of digoxin may be needed to maintain therapeutic drug concentrations. See prescribing information for digoxin.&nbsp;Theophylline&nbsp;Clinical Impact : Increased clearance of theophylline [see Clinical Pharmacology (12.3)].&nbsp;Intervention Individual patients may require additional titration of their theophylline dosage when Lansoprazole is started or stopped to ensure clinically effective blood concentrations.&nbsp;Drugs Dependent on Gastric pH for Absorption (e.g., iron salts, erlotinib, dasatinib, nilotinib, mycophenolate mofetil, ketoconazole/itraconazole)Clinical Impact:&nbsp; Lansoprazole can reduce the absorption of other drugs due to its effect on reducing intragastric acidity.&nbsp;Intervention:&nbsp; Mycophenolate mofetil (MMF): Co-administration of PPIs in healthy subjects and in transplant patients receiving MMF has been reported to reduce the exposure to the active metabolite, mycophenolic acid (MPA), possibly due to a decrease in MMF solubility at an increased gastric pH. The clinical relevance of reduced MPA exposure on organ rejection has not been established in transplant patients receiving Lansoprazole and MMF. Use Lansoprazole with caution in transplant patients receiving MMF.&nbsp; See the prescribing information for other drugs dependent on gastric pH for absorption.&nbsp;Combination Therapy with Clarithromycin and AmoxicillinClinical Impact:&nbsp; Concomitant administration of clarithromycin with other drugs can lead to serious adverse reactions, including potentially fatal arrhythmias, and are contraindicated. Amoxicillin also has drug interactions.&nbsp;Intervention:&nbsp;See Contraindications and Warnings and Precautions in prescribing information for clarithromycin.See Drug Interactions in prescribing information for amoxicillin.Tacrolimus&nbsp;Clinical Impact:Potentially increased exposure of tacrolimus, especially in transplant patients who are intermediate or poor metabolizers of CYP2C19.&nbsp;Intervention: Monitor tacrolimus whole blood trough concentrations. Dose adjustment of tacrolimus may be needed to maintain therapeutic drug concentrations. See prescribing information for tacrolimus.&nbsp;Interactions with Investigations of Neuroendocrine Tumors&nbsp;Clinical Impact:&nbsp; CgA levels increase secondary to PPI-induced decreases in gastric acidity. The increased CgA level may cause false positive results in diagnostic investigations for neuroendocrine tumors [see Warnings and Precautions (5.7), Clinical Pharmacology (12.2)].Intervention: Temporarily stop Lansoprazole delayed release capsules treatment at least 14 days before assessing CgA levels and consider repeating the test if initial CgA levels are high. If serial tests are performed (e.g., for monitoring), the same commercial laboratory should be used for testing, as reference ranges between tests may vary.&nbsp;Interaction with Secretin Stimulation TestClinical Impact: Hyper-response in gastrin secretion in response to secretin stimulation test, falsely suggesting gastrinoma.&nbsp;Intervention: Temporarily stop Lansoprazole treatment at least 28 days before assessing to allow gastrin levels to return to baseline [see Clinical Pharmacology (12.2)].False Positive Urine Tests for THC&nbsp;Clinical Impact:&nbsp; There have been reports of false positive urine screening tests for tetrahydrocannabinol (THC) in patients receiving PPIs.&nbsp;Intervention:&nbsp; An alternative confirmatory method should be considered to verify positive results.&nbsp;Table 3. Clinically Relevant Interactions Affecting Lansoprazole Delayed Release Capsules When CoAdministered with Other DrugsCYP2C19 OR CYP3A4 Inducers&nbsp;Clinical Impact:&nbsp; Decreased exposure of lansoprazole when used concomitantly with strong inducers [see Clinical Pharmacology (12.3)]Intervention:&nbsp; St John’s Wort, rifampin: Avoid concomitant use with Lansoprazole.Ritonavir-containing products: See prescribing information.&nbsp;CYP2C19 or CYP3A4 InhibitorsClinical Impact:&nbsp; Increased exposure of lansoprazole is expected when used concomitantly with strong inhibitors [see Clinical Pharmacology(12.3)].&nbsp;Intervention: Voriconazole: See prescribing information.&nbsp;Sucralfate&nbsp;Clinical Impact:&nbsp; Decreased and delayed absorption of lansoprazole [see Clinical Pharmacology (12.3)].&nbsp;Intervention :&nbsp; Take Lansoprazole at least 30 minutes prior to sucralfate [see Dosage and Administration (2.4)].&nbsp;

小唯快跑啊

要仅获取<p>下的标签7 DRUG INTERACTIONS,您可以使用 CSS 选择器:import requestsfrom bs4 import BeautifulSoupURL = "https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=00a574e0-bd03-deea-9f85-b108f78982ba"soup = BeautifulSoup(requests.get(URL).content, "html.parser")for tag in soup.select(&nbsp; &nbsp; "#anch_dj_dj-dj_9, [data-sectioncode='34073-7'] > p:nth-of-type(n+2)"):&nbsp; &nbsp; print(tag.get_text(strip=True))输出:7 DRUG INTERACTIONSTables 2 and 3 include drugs with clinically important drug interactions and interaction with diagnostics when administered concomitantly with lansoprazole delayed release capsules and instructions for preventing or managing them.Consult the labeling of concomitantly used drugs to obtain further information about interactions with PPIs.Table 2. Clinically Relevant Interactions Affecting Drugs Co-Administered with Lansoprazole Delayed Release Capsules and Interactions with DiagnosticsTable 3. Clinically Relevant Interactions AffectingLansoprazole Delayed Release CapsulesWhen CoAdministered with Other Drugs
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python