S
S
Sergey Nizhny Novgorod2015-11-03 02:58:03
Python
Sergey Nizhny Novgorod, 2015-11-03 02:58:03

How to parse generated link in Python?

Such question:
I write a parser for a site. At one point, where you need to take a link for further access, it is encapsulated and html does not see it. Those. for the user it is, but the parser sees not the link, but the js that generates it.
The link itself: https://examples/chats/view?chat_id=56399666&type=...
And the code that generates it and which the parser sees:

var transfer = (aData[9]) ? 'class="icon arrow-circle" title="'+'Принят от '+aData[9]+'"' : '';
                $('td:eq(6)', nRow).html('<span '+transfer+'>' + aData[6] + '</span>').find('.arrow-circle').tooltip();
                $('td:eq(7)', nRow).addClass('action');
                var link = (aData[8] == 'offline') ? 'offline_id' : 'chat_id';
               <b> link = '/chats/view?'+link+'='+aData[0]+'&type='+$type.val()+'&rating='+$rating.val()+
                                                '&period='+$period.val()+'&back='+backUrl;</b>
                if ($period.val() == 'other') {
                    link += '&from='+$("#dateFrom").val()+'&to='+$("#dateTo").val();
                }

                var removeLink = (aData[8] == 'offline') ? 'offline_id' : 'chat_id';
                removeLink = '/chats/remove?'+removeLink+'='+aData[0];
                $('td:eq(7)', nRow).html('<ul class="list-inline menu">' +
                   <b> '<li><a href="'+link+'" id="see" class="icon eye">Просмотр</a></li>'+</b>
                    '<li><a href="'+removeLink+'" id="remove" class="icon close-icon">Удалить</a></li></ul>');

                return nRow;

<b> '<li><a href="'+link+'" id="see" class="icon eye">Просмотр</a></li>'+</b>
- here is the link
Do not tell me, mb somehow it can be pulled out? Using requests and BeautifulSoup

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
angru, 2015-11-03
@Terras

I somehow already answered a similar question, in my opinion this approach is easier and cheaper than bothering with selenium/pyv8/phantomjs/etc

A
Avrong, 2015-11-03
@Avrong

What does the JS code do? There is an option - to port it to Python. Then the link will be generated directly from you.

D
devel787, 2015-11-05
@devel787

Perhaps something phantomjs.org will help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question