Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3314058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:11:15+00:00 2026-05-17T22:11:15+00:00

Nearing what I would like to think is completion on a tool I’ve been

  • 0

Nearing what I would like to think is completion on a tool I’ve been working on. What I’ve got going on is some code that does essentially this:

open several files and urls which consist of known malware/phishing related websites/domains and create a list for each, Parse the html of a url passed when the method is called, pulling out all the a href links and placing them in a separate list,

for every link that was placed in the new list, create a regex for every item thats in the malware and phishing lists, and then compare against to determine if any of the links parsed from the URL passed when the method was called are malicious.

The problem I’ve ran into is in iterating over the items of all 3 lists, obviously I’m doing it wrong since its throwing this error at me:

File "./test.py", line 95, in <module>
main()
File "./test.py", line 92, in main
crawler.crawl(url)
File "./test.py", line 41, in crawl
self.reg1 = re.compile(link1)
File "/usr/lib/python2.6/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.6/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: multiple repeat

The following is the segment of code I’m having problems with, with the malware related list create omitted as that part is working fine for me:

def crawl(self, url):
        try:
            doc = parse("http://" + url).getroot()
            doc.make_links_absolute("http://" + url, resolve_base_href=True)
            for tag in doc.xpath("//a[@href]"):
                old = tag.get('href')
                fixed = urllib.unquote(old)
                self.links.append(fixed)

        except urllib.error.URLERROR as err:
            print(err)

        for tgt in self.links:
            for link in self.mal_list:
                self.reg = re.compile(link)
            for link1 in self.phish_list:
                self.reg1 = re.compile(link1)

            found = self.reg.search(tgt)
            if found:
                print(found.group())
            else:
                print("No matches found...")

Can anyone spot what I’ve done wrong with the for loops and list iteration that would be causing that regex error? How might I fix it? And probably most importantly is the way I’m going about doing this ‘pythonic’ or even efficient? Considering what I’m trying to do here, is there a better way of doing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:11:15+00:00Added an answer on May 17, 2026 at 10:11 pm

    It seems like your problem is that some of the URLs contain special regex characters, such as ? and +; for instance, the string ++ is really quite likely. The other problem is that you keep overwriting the regex you’re using to test. If you just need to check if one string is contained in another, there’s no need for a regex; just use

    for tgt in self.links:
        for link in (self.mal_list + self.phish_list):
            if link in tgt: print link
    

    And if you’re just comparing for equality, you can use == instead of in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on an AS3 application and it's nearing completion. At the same
I've recently begun working on Django and now my app is nearing completion and
I'm nearing completion of my first app that utilizes (and requires) Game Center. I'm
I'm currently on a co-op term working on a project nearing completion with one
I am nearing completion of a project I am working on using Android, but
I've been working on a card game engine in C# .NET for some time
I've got a simple Drupal website set up and is nearing completion. This website
I have an Iphone app that was nearing its development completion and literally between
I am nearing completion of my first app that will be submitted to the
Java is nearing version 7. It occurs to me that there must be plenty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.