Please do not close this question - this is not a duplicate. I need to click the button using Python requests, not Selenium, as here
I am trying to scrape Reverso Context translation examples page. And I have a problem: I can get only 20 examples and then I need to click the "Display more examples" button lots of times while it exists on the page to get the full results list. It can simply be done using a web browser, but how can I do it with Python Requests library?
I looked at the button's HTML code, but I couldn't find an onclick
attribute to look at JS script attached to it, and I don't understand what request I need to send:
<button id="load-more-examples" class="button load-more " data-default-size="14px">Display more examples</button>
And here is my Python code:
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 protected]&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 word_pair in BeautifulSoup(html_text).find_all("div", id=re.compile("^OPENSUBTITLES")):
print(word_pair.find("div", class_="src ltr").text.strip(), "=", word_pair.find("div", class_="trg ltr").text.strip())
Note: you need to log in, otherwise it will show only first 10 examples and will not show the button. You may use this real authentication data:
E-mail: [email protected]
Password: sample
requests
. I have answered this question below. – Vulgusrequests
(I have described how to do this in more detail in the answer below). – Vulguspip
). AndSelenium
, in contradistinction torequests
, is browser-dependent and requires the chrome-driver to be installed manually by the user. – Vulgus