What do you do when you catch a Requests exception and you want to identify the URL that caused it? This script loops through a list of URLs and scrapes certain text. If one of the URLs fail in any way I catch it the Try Except block. All I can do now is print the "request error" string.
for url in urls:
try:
response = requests.get(url)
soup = BeautifulSoup(response.text, "lxml")
item = soup.find(string=re.compile("Grab and Go")) if soup.find(string=re.compile("Grab and Go")) else "N/A"
print(item)
except requests.exceptions.RequestException:
print("request error")
How can I identify the URL causing that error? Maybe something like:
except requests.exceptions.RequestException:
print("request error: {}".format(