I want MATLAB to pull restaurant names from Yelp

1 回表示 (過去 30 日間)
John Davies
John Davies 2020 年 4 月 3 日
回答済み: Jalaj Gambhir 2020 年 4 月 6 日
I want to pull restaurant names from Yelp when the user gives a location. Not sure how to get information other than the java. I built this using the help section.
citylocation=input('What is your City location? ','s');
statelocation=input('What is your State location? ','s');
link2web=(['https://www.yelp.com/search?find_desc=Restaurants&find_loc=',citylocation,'%2C+',statelocation,'&ns=1']);
%web(link2web)
url = [link2web];
S = webread(url);
options = weboptions('ContentType','text');
textData = webread(url,options)

回答 (1 件)

Jalaj Gambhir
Jalaj Gambhir 2020 年 4 月 6 日
Hi,
For your specific case, if you look at the textData returned (for say, citylocation = 'New York' and statelocation = 'NY'), you can observe that the results are stored in "og:description" tags' content property
The textData contains:
....
<meta property="og:description" content="Best Restaurants in New York, NY - Jacob&#39;s Pickles, Soco, Bunker...."> %%result truncated for readability
<meta property="og:site_name" content="Yelp">
....
So, you need to extract the text between these two tags. This can be easily achieved by 'regexp'
url = [link2web];
S = webread(url);
options = weboptions('ContentType','text');
textData = webread(url,options)
%% Use the following code:
pattern = '((?<=<meta property="og:description" content=").*(?=<meta property="og:site_name"))'
result = regexp(textData,pattern,'match')
This returns result as:
{'Best Restaurants in New York, NY - Jacob&#39;s Pickles, Soco, Bunker...'}

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by