T
T
Taya2019-05-28 18:17:29
Python
Taya, 2019-05-28 18:17:29

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">Магазин &quot;Дом натуральной косметики&quot;</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>

how do i get coordinates from onclick ?( '53.964127393', '27.6241564751' )

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Bezh, 2019-05-28
@Taya93

import re

string = '''onclick="MapWork('gm_1', '53.964127393', '27.6241564751')">'''
pattern = r", ?\'([\d\.]+)" 
result = re.findall(pattern,string)

print(result[0],result[1])

crutch
На случай, когда туго с регулярками
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])

M
Maxim, 2019-05-28
@Tomio

Somehow you can - https://regex101.com/r/mn2dm0/2/ - divided into 2 groups with coordinates

$pattern = "/onclick=\"\w+\(\'[\d_\w]+1\', ?\'([\d\.]+)\', ?\'([\d\.]+)\'\)\"/gmi";

V
Vyacheslav, 2019-06-24
@ElefanObi

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 globalis enabled in all cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question