mechanize._mechanize.LinkNotFoundError [英] mechanize._mechanize.LinkNotFoundError

查看:124
本文介绍了mechanize._mechanize.LinkNotFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此脚本模仿链接点击:

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)

但我收到此错误:

  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?

推荐答案

可能需要更多信息来帮助您更好,但是您是否尝试过

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)

或者也许

br.follow_link(text='theactualtextinthelink')

据我所知,以上内容当然不适用于图像

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

这篇关于mechanize._mechanize.LinkNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆