python - 是否可以使用 requests 模块从 Reverso Context 获取带有单词翻译的例句?

标签 python web-scraping python-requests urllib

我需要从Reverso Context获取带有单词翻译的例句。 .

首先,我尝试获取整个结果页面数据:

import requests


print(requests.get("https://context.reverso.net/translation/english-russian/cat").text)

我在这里遇到了一个问题 - 服务器知道我正在通过机器人访问它:我的应用程序没有得到我需要的东西,并且得到了这个:

<p class="text" id="text-en" style="display: none">
          You've been denied access â IP blacklisted<br/>
          Your IP <b class="ip"></b> has been considered as sending illegitimate traffic to our servers.<br/>
          If you think your traffic is legitimate, please fill in the form below so we could investigate why you were blacklisted.<br/><br/>
          Thank you,<br/>
          The Reverso Team
</p>

有没有办法欺骗服务器并获取带有示例的页面?

P.S.:我尝试为此网站查找 Python API,但找不到任何内容。

最佳答案

一旦您能够访问该网站,您就可以找到这样的例句。

req = requests.get("https://context.reverso.net/translation/english-russian/cat", headers={'User-Agent': 'Mozilla/5.0'})

soup = BeautifulSoup(req.text, 'lxml')

sentences = [x.text.strip() for x in soup.find_all('span', {'class':'text'}) if '\n' in x.text]

>>> sentences[:4]
['My cat stepped on the remote.', 'Я не смотрю твои бредни, мой кот наступил на пульт.', 'Now imagine you have a cat...', 'А теперь представьте, что у вас есть кот...']

关于python - 是否可以使用 requests 模块从 Reverso Context 获取带有单词翻译的例句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60342192/

相关文章:

使用正则表达式拆分 Python 字符串

python - 为什么Scrapy不爬取或解析?

python - 使用 selenium 抓取 bet365.com 时出现的最后一个问题

Python3无法建立连接socket.gai错误: Name or service not known

python - 请求 : post multipart/form-data

python - ffmpeg使用python子进程设置文件名模式

python - Django F() 对象和自定义保存怪异

python - 导入错误: No module named _multiprocessing

python - "TypeError: object of type ' 响应 ' has no len()"

python - 抓取 protected 电子邮件