python3判断url链接是否为404的方法
作者:iszzs 时间:2021-11-12 15:17:54
本文实例为大家分享了python3判断url链接是否为404的具体代码,供大家参考,具体内容如下
import pymysql
import threading
import time
import urllib
import requests
# 打开数据库连接
db = pymysql.connect("192.168.0.*", "username", "password", "databasename")
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# SQL 查询语句
sql = "SELECT sku,url_6 FROM url_new where flag_6 is null and url_6<>'' "
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
num = 0
for row in results:
sku = row[0]
url = row[1]
html = requests.head(url) # 用head方法去请求资源头
re=html.status_code
num = num + 1
print(num,re)
if re == 200:
sql_2 = "UPDATE url_new SET flag_6 = 0 WHERE sku = '%s'" % sku
try:
# 执行SQL语句
cursor.execute(sql_2)
#print(cursor.rowcount)
except Exception as e:
print(e)
conn.rollback()
if re == 404:
sql_3 = "UPDATE url_new SET flag_6 = 1 WHERE sku = '%s'" % sku
try:
# 执行SQL语句
cursor.execute(sql_3)
print(cursor.rowcount)
except Exception as e:
print(e)
conn.rollback()
db.commit()
db.close()
来源:https://blog.csdn.net/u013091109/article/details/80737422
标签:python3,url,404
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
实现asp长文章自动分页插件
2011-02-26 13:51:00
centos 安装mysql中遇到问题的解决办法
2010-12-14 15:11:00
详解TensorFlow2实现线性回归
2022-11-10 15:35:13
![](https://img.aspxhome.com/file/2023/2/92512_0s.jpg)
Oracle 8i字符集乱码问题析及其解决办法
2010-07-26 13:29:00
Python使用pyserial进行串口通信的实例
2022-03-07 15:30:09
在Python中append以及extend返回None的例子
2021-05-12 10:33:34
![](https://img.aspxhome.com/file/2023/1/97201_0s.jpg)
SQL 2008 FileStream数据类型
2008-10-28 21:07:00
python输出带颜色字体实例方法
2021-03-27 22:40:56
![](https://img.aspxhome.com/file/2023/4/97624_0s.png)
python+django加载静态网页模板解析
2022-06-14 16:58:47
![](https://img.aspxhome.com/file/2023/4/97754_0s.png)
Python是什么 Python的用处
2021-12-20 05:55:37
Python使用PyYAML库读写yaml文件的方法
2021-03-26 03:53:32
通过分析SQL语句的执行计划优化SQL
2011-10-24 20:03:20
PyQt5实现进度条与定时器及子线程同步关联
2023-03-20 14:48:35
![](https://img.aspxhome.com/file/2023/5/88875_0s.gif)
Python实现京东抢秒杀功能
2021-12-06 04:50:17
![](https://img.aspxhome.com/file/2023/8/71558_0s.png)
python执行系统命令后获取返回值的几种方式集合
2022-07-24 22:43:56
对python 中class与变量的使用方法详解
2023-12-27 19:22:10
python+opencv实现的简单人脸识别代码示例
2021-06-15 01:02:27
![](https://img.aspxhome.com/file/2023/1/76861_0s.jpg)
二级域名原理以及asp实现程序
2007-08-03 13:08:00
python实现ping命令小程序
2022-12-14 02:16:26
![](https://img.aspxhome.com/file/2023/9/75159_0s.png)
Pycharm最全报错的原因与解决方法总结(推荐!)
2023-10-26 04:20:03
![](https://img.aspxhome.com/file/2023/4/79534_0s.jpg)