在机械化中,我们使用follow_link或click_link单击链接.在美丽的汤中是否有类似的东西点击网页上的链接?
请不要关闭这个问题 - 这不是重复的。我需要使用 Python 请求而不是 Selenium 单击按钮,如下所示
我正在尝试抓取Reverso Context 翻译示例页面。我有一个问题:我只能获取 20 个示例,然后我需要在页面上存在“显示更多示例”按钮时多次单击它才能获取完整的结果列表。使用网络浏览器就可以轻松完成,但是如何使用 Python Requests 库来完成呢?
我查看了按钮的 HTML 代码,但找不到查看onclick附加到其上的 JS 脚本的属性,并且我不明白需要发送什么请求:
<button id="load-more-examples" class="button load-more " data-default-size="14px">Display more examples</button>
Run Code Online (Sandbox Code Playgroud)
这是我的 Python 代码:
from bs4 import BeautifulSoup
import requests
import re
with requests.Session() as session: # Create a Session
# Log in
login_url = 'https://account.reverso.net/login/context.reverso.net/it?utm_source=contextweb&utm_medium=usertopmenu&utm_campaign=login'
session.post(login_url, "Email=reverso.scraping@yahoo.com&Password=sample",
headers={"User-Agent": "Mozilla/5.0", "content-type": "application/x-www-form-urlencoded"})
# Get the HTML
html_text = session.get("https://context.reverso.net/translation/russian-english/cat", headers={"User-Agent": "Mozilla/5.0"}).content
# And scrape it
for …Run Code Online (Sandbox Code Playgroud)