import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.preparedfoods.com/articles/106989-irish-pork-crisis')
soup = BeautifulSoup(r.content, 'html.parser')
print(soup.title)
s = soup.find('div', class_='entry-content')
lines = s.find_all('p')
for line in lines: print(line.text)
Irish Pork Crisis | Prepared FoodsAttributeError Traceback (most recent call last) in () 17 s = soup.find('div', class_='entry-content') 18 ---> 19 lines = s.find_all('p') 20 21 for line in lines:
AttributeError: 'NoneType' object has no attribute 'find_all'
CodePudding user response:
Add the lines inside if
block
s = soup.find('div', class_='entry-content')
if s is not None:
lines = s.find_all('p')
for line in lines: print(line.text)
CodePudding user response:
Can you explain your problem please ?