am trying to write an exception while parsing a link:
import requests
from bs4 import BeautifulSoup
IDFile = open('IDs.csv')
IDReader = csv.reader(IDFile)
ID = list(IDReader)
for row in ID:
col1,col2 = row
ID ="%s" % (col2)
url = requests.get("http://.......")
soup = BeautifulSoup(url.text, "lxml")
print(soup)
## execute more code if "results:" is greater than zero
The output of "print(soup)" is:
<html><body><p>{ success:true ,results:0,rows:[], ID:5432}</p></body></html>
The IDs.csv contains:
14-Aug-2015,5431
30-May-2015,5432
17-Feb-2015,5433
I want to write an exception where:
if output of "print(soup) has "results:0", then APPEND the variable ID (5432 in this case) to zero-results.txt file and process the next id (5433) from my ids.csv file.
else if output of "print(soup) has "result:1" or greater, then continue to process the remaining code
Please help, thanx
element 2) use python JSON module to parse it 3) extract results
– Andrey Oct 09 '15 at 14:04