Answer the question
In order to leave comments, you need to log in
How to get coordinates from onclick with regular expressions?
there is html code
<div class="shop_descr">
<div class="shop_city">Минск</div>
<div class="shop_name">Магазин "Дом натуральной косметики"</div>
<a href="#top" title="показать на карте" class="shop_addr spec_decor"
onclick="MapWork('gm_1', '53.964127393', '27.6241564751')">
<i class="glyphicon glyphicon-map-marker"></i>
<span class="dotted">ТЦ Expobel, пересечение ул. Мирошниченко и МКАД</span></a>
<div class="shop_phone">
<a href="tel:+375172379448"
class="phone_link">+375 (17) 237-94-48</a><br/>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
import re
string = '''onclick="MapWork('gm_1', '53.964127393', '27.6241564751')">'''
pattern = r", ?\'([\d\.]+)"
result = re.findall(pattern,string)
print(result[0],result[1])
import re
string = '''onclick="MapWork('gm_1', '53.964127393', '27.6241564751')">'''
result = re.findall(r'onclick="MapWork(.+?)"',string)
res = re.findall("'(.+?)'",str(result))
print(res[1],res[2])
Somehow you can - https://regex101.com/r/mn2dm0/2/ - divided into 2 groups with coordinates
$pattern = "/onclick=\"\w+\(\'[\d_\w]+1\', ?\'([\d\.]+)\', ?\'([\d\.]+)\'\)\"/gmi";
If only coordinates are needed and you know for sure that there are no other strings similar to coordinates.
If there are other similar strings, then you can first get a string with arguments from MapWork
and then parse the resulting string with the first expression.
The flag global
is enabled in all cases.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question