0

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

#!/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

我的代码片段有什么问题以及如何解决?

4

1 回答 1

0

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

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

也许

br.follow_link(text='theactualtextinthelink')

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

于 2013-11-06T04:27:35.770 回答