Skip to content Skip to sidebar Skip to footer

How Do You Parse And Match The Keyword In Search Engine Url Using Python Re Module?

Example from Google: http://www.google.com.co/url?sa=t&rct=j&q=pedro%20gomez%20proyecto%20en%20la%20ciudad%20de%20valledupar&source=web&cd=10&ved=0CFsQFjAJ&

Solution 1:

Try this:

[?&]q=([^&#]*)

Or, better yet:

importurlparsepr= urlparse.urlparse(url)
qs = urlparse.parse_qs(pr.query)['q']

The latter automatically decodes %-escapes, too.

Post a Comment for "How Do You Parse And Match The Keyword In Search Engine Url Using Python Re Module?"