Python Forum
web scraping with python regular expression
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
web scraping with python regular expression
#6
Example to get reviews with regex.
import urllib.request
from re import findall
import re
from pprint import pprint

url = "https://www.yelp.com/search?find_desc=Restaurants+Mexican&find_loc=Dallas%2C+TX&ns=1"
response = urllib.request.urlopen(url)
html = response.read()
htmlStr = html.decode()

r = re.findall(r'\d+\s\breviews\b', htmlStr)
pprint(r)
Output:
['251 reviews',  '1209 reviews',  '295 reviews',  '389 reviews',  '143 reviews',  '351 reviews',  '364 reviews',  '394 reviews',  '598 reviews',  '341 reviews',  '214 reviews']
Reply


Messages In This Thread
RE: web scraping with python regular expression - by snippsat - Sep-25-2017, 09:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression rakhmadiev 6 5,560 Aug-21-2023, 01:52 PM
Last Post: Gribouillis
  BeautifulSoup : how to have a html5 attribut searched for in a regular expression ? arbiel 2 2,722 May-09-2020, 03:05 PM
Last Post: arbiel
  Extract text from tag content using regular expression Pavel_47 8 5,446 Nov-25-2019, 03:17 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020