下面是获取http响应的代码:
import requests
import xlrd
import xlwt
file_location = "C:/Users/Nitin Kansal/Desktop/rc/Cashkaro.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
urls = []
for r in range(sheet.nrows):
urls.append(sheet.cell_value(r,0))
book = xlwt.Workbook(encoding = "utf-8", style_compression = 0)
sheet = book.add_sheet("Sheet1", cell_overwrite_ok = True)
for index, url in enumerate(urls):
r_response = requests.head(url)
try:
Response_Number = r_response.status_code
sheet.write(index, 0, url)
sheet.write(index, 1, Response_Number)
except Exception:
sheet.write(index, 0, url)
sheet.write(index, 1, "Failed to Fetch Response")
book.save("Response Output.xls")
下面是网址,保存到excel中,我添加了一个不存在的网址“nitinkansal121.com”。这打破了密码。如果这个网址被删除,他们的代码运行良好
https://clk.omgt5.com/?AID=183476&PID=9319&WID=33968
http://clk.omgt5.com/?AID=183476&PID=9166&WID=33968
http://clk.omgt5.com/?AID=183476&PID=14173&WID=33968
http://www.nitinkansal121.com/
http://clk.omgt5.com/?AID=183476&PID=9394&WID=33968
requests.head
如果在不存在的域上传递URL,则会引发异常您可以替换:
比如:
相关问题 更多 >
编程相关推荐