import requests
from bs4 import BeautifulSoup
import pandas as pd
import pdfkit
import re
URL = 'https://timesofindia.indiatimes.com/'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'lxml')
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'lxml')
all_links=set()
for link in soup.find_all('a'):
all_links.add(link.get('href'))
s = list(all_links)
print(s)
x=[i for i in s if i._contains_(URL)]
m=[]
find_words= ['cbse', 'first-day']
for s in x:
if any(f in s for f in find_words):
m.append(s)
print(m)
Asked
Active
Viewed 132 times
-3

DYZ
- 55,249
- 10
- 64
- 93
-
Does [this](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) answer your question? – DYZ Jul 17 '20 at 06:27
1 Answers
0
your contains line is not valid.
Try
x=[i for i in s if URL in i]

ewokx
- 2,204
- 3
- 14
- 27
-
I tried using 'in' but it is still not working. Can you help me out please? – Ritvik Palvankar Jul 19 '20 at 07:33