943,102 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 203
  • Python RSS
Feb 8th, 2010
0

Regex problem

Expand Post »
Hello... I have problem with regex, I want to get the tables from another site... the regex is re.compile(r'<table.*?>(.*?)</table>') but when I get the tables I don't know how to return the value into the tables.

Python Syntax (Toggle Plain Text)
  1. #html = the page
  2. tbl = re.compile(r'<table.*?>(.*?)</table>')
  3. return tbl.sub('', html) #return html without <table>...</table>
  4. # how to return the value only of <table> tags... without the other tags ?

Thanks.
Similar Threads
Reputation Points: 17
Solved Threads: 5
Junior Poster
Krstevski is offline Offline
110 posts
since May 2009
Feb 8th, 2010
0
Re: Regex problem
Click to Expand / Collapse  Quote originally posted by Krstevski ...
Hello... I have problem with regex, I want to get the tables from another site... the regex is re.compile(r'<table.*?>(.*?)</table>') but when I get the tables I don't know how to return the value into the tables.

Python Syntax (Toggle Plain Text)
  1. #html = the page
  2. tbl = re.compile(r'<table.*?>(.*?)</table>')
  3. return tbl.sub('', html) #return html without <table>...</table>
  4. # how to return the value only of <table> tags... without the other tags ?

Thanks.
I suggest
python Syntax (Toggle Plain Text)
  1. the_list = tbl.findall(html)
There is also finditer which returns a sequence of match objects.
Reputation Points: 927
Solved Threads: 666
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Feb 8th, 2010
0
Re: Regex problem
I suggest
python Syntax (Toggle Plain Text)
  1. the_list = tbl.findall(html)
There is also finditer which returns a sequence of match objects.
Thanks man, it works
Reputation Points: 17
Solved Threads: 5
Junior Poster
Krstevski is offline Offline
110 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: problems with posting to forms with twill
Next Thread in Python Forum Timeline: ImportError





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC