Python engine tracking image links?

the mechanize Browserclass is great, and the follow_link () function is great too. But what to do with these types of links:

<a href="http://example.com"><img src="…"></a>

Is there any way to track such links? The attribute of textthis type of link is simple '[IMG]', so AFAIK there is no way to differentiate such links. Any help would be appreciated.

+3
source share
1 answer

To follow such links, you need to add the nr parameter to the follow_link () method .
Try the following:

import mechanize
br = mechanize.Browser()
br.open('http://www.systempuntoout.com')
for link in br.links():
    print(link)
br.follow_link(text='[IMG]', nr=0)
print br
>>><Browser visiting http://www.systempuntoout.com/quiz>
br.back()
br.follow_link(text='[IMG]', nr=1)
>>><Browser visiting http://www.systempuntoout.com/about>
+5
source

Source: https://habr.com/ru/post/1739003/


All Articles