Within the following code, I can't get past the first if
statement and proceed to the else statement
, even when I purposely make it false:
while not scraped:
print("sleep....")
time.sleep(1)
try:
res = requests.get(url).content
soup = BeautifulSoup(res, 'lxml')
links = soup.find_all("span", {"id":"reasonabledoubt"})
dip = soup.find_all("div")
print("searching divs")
if 'keyword' in str(dip) == True:
print(url)
print("LINK SCRAPED")
print(url + " link scraped")
scraped = True
else:
for word in links:
print("testing for loop")
#rest of code
So basically if the keyword isn't found in str(dip), I need the else clause to execute.