Im new to Python and trying to import a list of urls from a csv and check the header status of each. So far ive got the following which prints the list of urls:
import csv
from requests_html import HTMLSession
from bs4 import BeautifulSoup
import requests
with open('list.csv', 'r') as f:
reader = csv.reader(f)
for row in reader:
url = " ".join(row)
print(url)
I now want to print the header status code next to each url, so ive tried this which doesnt work. Any help would be appreciated:
with open('list.csv', 'r') as f:
reader = csv.reader(f)
for row in reader:
url = " ".join(row)
headers = requests.head(url.get('href'))
print(url, (headers.status_code))
The error i get is:
headers = requests.head(url.get('href')) AttributeError: 'str' object has no attribute 'get'
I need to output something like:
https://www.domainone.com 200
https://www.domaintwo.com 200
https://www.domainthree.com 404