0

Hi im currently trying to study python and what i have at the minute im trying to regex one site then depending on the results send through different def's to get end results. Ill show a rough example underneath. Ive looked at threading but not 100% if its what i want or how to implement it, what i am trying to do is speed up the process as can take a while to compile my list at the end. Heres a rough example

def main regex():
     match = etc
     for result in match:
         If 'a' in result:
             A(result)
         elif 'b' in result:
             B(result)
         elif 'c' in result:
             C(result)
         And so on....

def A(result):
    Match = etc
    for result in Match:
        print result

def B(result):
    Match = etc
    for result in Match:
        print result

def C(result):
    Match = etc
    for result in Match:
        print result

And so on so at the end it compiles a list of 'results' However am finding it takes a fair bit of time and wondered if there was a way to speed up the process. Many thanks in advance.

P.s. this isnt the exact code just a rough example of what im trying to achieve

toall1985
  • 34
  • 6
  • Python is case-sensitive, so your mixed-case keywords won't work. – Tom Karzes Feb 11 '16 at 08:16
  • 3
    Why are you worried about performance before you have working code? – msw Feb 11 '16 at 08:20
  • Sorry that is my phone ill edit. The actual code i have is a lot more complex and works fine just it is at home on computer so this is just rough to show what im trying to achieve – toall1985 Feb 11 '16 at 08:22
  • If your code works, then you should post it on https://codereview.stackexchange.com/ – OneCricketeer Feb 11 '16 at 08:28
  • Also, If by "site" you mean "website" - Please [don't use regex for parsing HTML](http://stackoverflow.com/a/1732454/2308683) – OneCricketeer Feb 11 '16 at 08:31
  • Ok sorry wasnt sure where to ask as its not the code thats the concern just wondered if theres a way to speed up the process. Ill repost if i can get on my computer in next couple of days. Thanks for replys and sorry to have wasted time – toall1985 Feb 11 '16 at 08:32
  • Ok i see this is a touchy subject that occurs a lot. What is the prefered method to grab information from websites? I apologise for my ignorance in this matter – toall1985 Feb 11 '16 at 08:36
  • Are you sure it's the regex code that's slow and not the code that fetches the webpage? Try running cProfile on your code to see what the bottleneck is. – Brian Schlenker Feb 11 '16 at 09:07
  • cProfile isnt something in familiar with but will research it thank you will be handy to know. Thanks for responding im only a few months into learning so is a little hard/demoralising pestering people. – toall1985 Feb 11 '16 at 09:16
  • Then try [lxml](http://lxml.de/) to parse X(HT)ML. – rypel Apr 09 '16 at 09:00
  • Also, consider these guides on [asking questions](https://stackoverflow.com/help/how-to-ask), [providing examples](https://stackoverflow.com/help/mcve), [adding tags](https://stackoverflow.com/help/tagging) and [formatting](https://stackoverflow.com/help/formatting). – rypel Apr 09 '16 at 09:10

0 Answers0