mechanize._mechanize.LinkNotFoundError

本小妞迷上赌 提交于 2019-12-25 04:50:35

问题


I try to imitate a link click using this script:

#!/usr/bin/env python

import mechanize

targetPage = 'http://example.com/'
clickUrl="http://someurlinsideexample.com/" 

br = mechanize.Browser(factory=mechanize.RobustFactory())
br.open(targetUrl)
br.follow_link(url=clickUrl)

but I get this error:

  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 620, in find_link
    raise LinkNotFoundError()
mechanize._mechanize.LinkNotFoundError

What's wrong with my snippet and how to fix it?


回答1:


Probably need a bit more info to help you better, but have you tried

for link in br.links():
    if link.url == clickUrl:
        br.follow_link(link)

or perhaps

br.follow_link(text='theactualtextinthelink')

of course the above wont work for images as far as i know



来源:https://stackoverflow.com/questions/19803075/mechanize-mechanize-linknotfounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!