I
I
Ilya Fateev2014-04-08 01:07:41
Python
Ilya Fateev, 2014-04-08 01:07:41

How to get a full VKontakte page using python?

How to get the code of the page VKontakte (mobile version) in python?
For example, if I just do it something like this:

...
def download_page(self, url):
        opener = urllib2.build_opener()
        opener.addheaders = [('Cookie', self._cookie),
                             ('User-Agent', self._user_agent),
                             ('Accept-Charset', 'utf-8')]
        page = opener.open(url)
        page_string = page.read().decode('utf-8')

url = "https://m.vk.com/id1?z=photo1_326502705%2Fphotos1"
print blabla.download_page(url)
...

Then I will not get the full code of the page. Apparently, this is due to AJAX. That is, the question comes down to how you can do AJAX requests (I don't know how to formulate this correctly :( ) using python.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Valentine, 2014-04-08
@fat32nov

Ajax request - XMLHttpRequest, it can also be created in python. Cookies can also be added to it all the necessary ones. It is also possible to form GET or POST.

S
Sergey, 2014-04-08
Protko @Fesor

Maybe you didn’t know, but an AJAX request is a regular HTTP request, and in the context of the task you need to generate the correct headers, which, to be honest, is problematic, given the VKontakte authentication / authorization mechanisms (although maybe everything is simpler there than I think).
And why not use the VKontakte API and work directly with the data, bypassing the process of stupid html parsing (as I understand it, everything is done for this).

D
DrunkMaster, 2015-08-28
@victorib_us

preg_match_all("/(^|\s)один(\s|$)/",$text);
Beginning of line or surrounded by spaces or end of line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question