【问题标题】:Problems with running GTK3+ Python GUI for a web crawler为网络爬虫运行 GTK3+ Python GUI 的问题
【发布时间】:2015-11-27 14:04:15
【问题描述】:

我的程序是一个基于 Python 的网络爬虫,它通过 Linux 发行版(使用 Ubuntu 14)上的终端命令提取数据。 现在,自从我为它实现了 GT3+ GUI 后,我得到了以下错误:

/usr/bin/python3.4 /home/dipeshwar/Documents/WebsiteScanner/main.py Traceback(最后一次调用):文件

“/home/dipeshwar/Documents/WebsiteScanner/main.py”,第 81 行,在 button_clicked 收集信息(self.name,self.url)文件“/home/dipeshwar/Documents/WebsiteScanner/main.py”,第 44 行,在 收集信息 domain = get_domain_name(url) 文件“/home/dipeshwar/Documents/WebsiteScanner/domain.py”,第 16 行,在 获取域名 domain = get_tld(url) 文件“/usr/local/lib/python3.4/dist-packages/tld/utils.py”,第 161 行,在 获取域名 url = url.lower() AttributeError: 'Entry' 对象没有属性 'lower' 这是我的代码。你能告诉我为什么它给我这个错误吗? 在 get_doman_name 函数中,我只是使用 Python 中的 'tld' 模块来获取顶级域。

问候

from gi.repository import Gtk
# import statement for GUI
from general import *
from whois import *
from domain import *
from ipadd import *
from nmap import *
from robots_txt import *
# these import statements get all the variables from other modules of this program

ROOT_DIR = 'Output'
create_dir(ROOT_DIR)
# Checks if directory is created or not, if not, the program creates it

def create_report(name, url, domain, ipadd, nmap, robots_txt, whois): # or def create_report(name, full_url, domain, ipadd, nmap, robots_txt, whois): ?

    project_dir = ROOT_DIR + '/' + name
    create_dir(project_dir)
    write_file(project_dir + '/full_url.txt', url) # or full_url ?
    write_file(project_dir + '/domain.txt', domain)
    write_file(project_dir + '/ipadd.txt', ipadd)
    write_file(project_dir + '/nmap.txt', nmap)
    write_file(project_dir + '/robots_txt.txt', robots_txt)
    write_file(project_dir + '/whois.txt', whois)



def gather_info(name, url):
    domain = get_domain_name(url)
    ipadd = get_ip_address(url)
    nmap = get_nmap(ipadd)
    robots_txt = get_robots_txt(url)
    whois = get_whois(url)
    create_report(name, url, domain, ipadd, nmap, robots_txt, whois)


class MainWindow(Gtk.Window):


    def __init__(self):
        Gtk.Window.__init__(self, title="Reconnaissance Web-Scanner")
        self.set_border_width(30)
        self.set_size_request(300, 200)

        # Layout of window
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
        self.add(vbox)

        # Inputs
        self.name = Gtk.Entry()
        self.name.set_text("Enter name of website here:")
        vbox.pack_start(self.name, True, True, 0)

        self.url = Gtk.Entry()
        self.url.set_text("Enter URL of website here:")
        vbox.pack_start(self.url, True, True, 0)


        # Button
        self.button = Gtk.Button(label="Scan Website")
        self.button.connect("clicked", self.button_clicked)
        vbox.pack_start(self.button, True, True, 0)

    # when user clicks the button    
    def button_clicked(self, widget):
        gather_info(self.name, self.url)
        # put exec code here

【问题讨论】:

    标签: python pygtk


    【解决方案1】:

    self.nameself.url 都是 Gtk.Entrys 而不是字符串。因此,您必须将代码更改为:

        def button_clicked(self, widget):
            gather_info(self.name.get_text(), self.url.get_text())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多