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: import import code import code urlib2 page = urllib2.urlopen ("http: // www. M.funtweets.com/random ") .read () user = re.compile ('& lt; span & gt; @ & lt; / span & gt; (\ w +)') text = re.compile (r Group (1), Regent (text, page) for match in & lt; / b & gt; & lt; / a & gt; (\ w. *) ") User_lst = [match reader (user, page)] Match_list = '@ {0} \ n {1} \ n'.format (_user, _text) for match in ridgeet (user, list), match_list =' @

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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -