如何使用mechanize在网页上获取链接并打开这些链接

时间:2022-11-23 17:42:10

I want to use mechanize with python to get all the links of the page, and then open the links.How can I do it?

我想使用机械化与python来获取页面的所有链接,然后打开链接。我怎么能这样做?

2 个解决方案

#1


Here is an example from the project's page:

以下是项目页面中的示例:


import re
from mechanize import Browser

br = Browser()
br.open("http://www.example.com/")

# ...

# .links() optionally accepts the keyword args of .follow_/.find_link()
for link in br.links(url_regex="python.org"):
    print link
    br.follow_link(link)  # takes EITHER Link instance OR keyword args
    br.back()

#2


The Browser object in mechanize has a links method that will retrieve all the links on the page.

mechanize中的Browser对象有一个links方法,可以检索页面上的所有链接。

#1


Here is an example from the project's page:

以下是项目页面中的示例:


import re
from mechanize import Browser

br = Browser()
br.open("http://www.example.com/")

# ...

# .links() optionally accepts the keyword args of .follow_/.find_link()
for link in br.links(url_regex="python.org"):
    print link
    br.follow_link(link)  # takes EITHER Link instance OR keyword args
    br.back()

#2


The Browser object in mechanize has a links method that will retrieve all the links on the page.

mechanize中的Browser对象有一个links方法,可以检索页面上的所有链接。