Add url to table.

This commit is contained in:
luming 2023-09-19 11:39:20 +08:00
parent 2f01c0187a
commit ac6068e13f

29
dm.py
View File

@ -1,6 +1,7 @@
import logging
import socket
import sys
from urllib.parse import urlparse
import pymysql
from PySide6 import QtWidgets
@ -169,14 +170,32 @@ class TableWidgetExample(QMainWindow):
text = self.input_text.toPlainText()
if not text.strip():
self.logger.debug("Content is empty")
return # 如果文本为空,则不添加任何行
return
lines = text.split('\n')
self.table.setRowCount(len(lines))
for row, line in enumerate(lines):
item = QTableWidgetItem(line)
url = QTableWidgetItem(line)
# 校验url是否合法
if not self.is_valid_url(line):
self.logger.debug("url is invalid")
self.statusBar().showMessage("存在无效的url")
continue
row_position = self.table.rowCount() # 获取下一个可用的行索引
self.table.insertRow(row_position)
status = QTableWidgetItem("队列中")
self.table.setItem(row, 0, item)
self.table.setItem(row, 1, status)
self.table.setItem(row_position, 0, url)
self.table.setItem(row_position, 1, status)
def is_valid_url(self, url):
try:
parsed_url = urlparse(url)
# 检查是否有有效的协议和主机
if parsed_url.scheme and parsed_url.netloc:
return True
else:
return False
except Exception as e:
return False
if __name__ == "__main__":
app = QApplication(sys.argv)