Issue
this is my code
import requests
from bs4 import BeautifulSoup
req = requests.get('https://www.healthline.com/nutrition/13-acne-remedies#acv')
soup = BeautifulSoup(req.content, "html.parser")
soup1 = str(soup.prettify)
for i in soup1:
a=soup1.index(i)
if soup1[a:a+7]=="header":
print(soup1[a+9:a+30])
else:
pass
soup1 contains 50 headers but still I don't get any output
Can someone guide me through this?
Solution
Change : soup1[a:a+7]=="header"
to soup1[a:a+6] == header":
and print to print(soup1[a+9:a+30])
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy as sp
import requests
from bs4 import BeautifulSoup
url = 'https://www.healthline.com/nutrition/13-acne-remedies#acv'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
soup1 = str(soup.prettify)
for a in range(len(soup1)):
if soup1[a:a+6] == "header":
print(soup1[a+9:a+30])
else:
pass
Please find the working code attached here.
Answered By - Selaka Nanayakkara
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.