在python中使用beautifulsoup点击链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23679480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:18:34  来源:igfitidea点击:

Clicking link using beautifulsoup in python

pythonweb-scrapingbeautifulsoup

提问by user3286661

In mechanize we click links either by using follow_link or click_link. Is there a similar kind of thing in beautiful soup to click a link on a web page?

在机械化中,我们通过使用 follow_link 或 click_link 单击链接。美汤里有没有类似的东西点击网页上的链接?

采纳答案by alecxe

BeautifulSoupis an HTML parser.

BeautifulSoup是一个 HTML解析器

Further discussion really depends on the concrete situation you are in and the complexity of the particular web page.

进一步的讨论实际上取决于您所处的具体情况以及特定网页的复杂性。

If you need to interact with a web-page: submit forms, click buttons, scroll etc - you need to use a tool that utilizes a real browser, like selenium.

如果您需要与网页交互:提交表单、单击按钮、滚动等 - 您需要使用使用真实浏览器的工具,例如selenium.

In certain situations, for example, if there is no javascript involved in submitting a form, mechanizewould also work for you.

在某些情况下,例如,如果提交表单时不涉及 javascript,它mechanize也适用于您。

And, sometimes you can handle it by simply following the link with urllib2or requests.

而且,有时您可以通过简单地跟随带有urllib2或的链接来处理它requests