0

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
1
  • What doesn't work exactly? Do you see any errors, if yes it will really help to put that in your post. Commented Mar 17, 2020 at 16:41

1 Answer 1

1

you already have the url and the response. just print them out:

resp = requests.head(url)
print('%s %d' % (url, resp.status_code))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.