I’m using Requests to scrape a website. The content of the html gets successfully saved in the variable r but in the if-statement I get the said error
[...]
for line in r:
link = re.findall(r ("""onclick="window.location.href='([^'])'""",line)
if link:
print ('something')
cmd = ('some commands to get info page')
call(cmd,shell=True)
download = re.sub(something)
cmd = ('some commands to download the file')
call(cmd,shell=True)
r.close()
I looked it up in the documentation and the syntax appears to be correct. I then suspected the error to be in the line before. Here I search for the line with the phrase onclick=”window.location.href=’ and want the link that follows it to be processed (in the code afterwards). The () encapsuled part should be what is returned, right?
Does anybody see an error? in
Perhaps the brackets?
It looks like you forgot to close the bracket for findall.