python - Using regular expressions to parse HTML -
I'm new to Python. A codeer gave me some code to parse the HTML. I'm having trouble understanding how it works. To get my idea from funtweets.com/random (Consumption?) Is for HTML and basically tell me a funny joke as an alarm clock in the morning It currently takes all jokes on the page and only one Only need. Either code can be modified or detailed as to how the code works. This code will be helpful to me: user3530608 Do you want a match instead of playing again through matches? This is a great way to get started with Python Regular Expression. Here is a small tweak for your code. I do not have a dragon to check the dragon in front of me, so tell me if you run on any issue.
import import urllib2 page = urllib2.urlopen ("http: // www.m.funtweets.com/random"). Read () umatch = re.search (r "span & gt; @ (\ w +)", page) user = umatch.group () utext = re.search (r) "& Lt; / b & gt; & lt; / a & gt; (\ w. *)", Page) text = utext.group () print '@ {0} \ n {1} \ n'.format (User, text)
Comments
Post a Comment