#python #python-3.x #web-scraping #python-requests #python-requests-html
#питон #python-3.x #соскабливание полотна #python-запросы #python-requests-html
Вопрос:
Я пытаюсь соскрести заголовки с medium.com
помощью этой библиотеки, которая называется requests_html
Код, который я использую, хорошо работает на других компьютерах, но не на моем.
Вот как выглядит исходный код следующим образом:
from requests_html import HTMLSession
session = HTMLSession()
r = session.get('https://medium.com/@daranept27')
r.html.render()
x = r.html.find('a.eg.bv')
[print(elem.text) for elem in x]
Это дает мне pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 8000 ms exceeded.
Вот полная ошибка:
Traceback (most recent call last):
File "C:UsersintelDesktophackerrank.py", line 5, in <module>
r.html.render()
File "C:UsersintelAppDataLocalProgramsPythonPython38libsite-packagesrequests_html.py", line 598, in render
content, result, page = self.session.loop.run_until_complete(self._async_render(url=self.url, script=script, sleep=sleep, wait=wait, content=self.html, reload=reload, scrolldown=scrolldown, timeout=timeout, keep_page=keep_page))
File "C:UsersintelAppDataLocalProgramsPythonPython38libasynciobase_events.py", line 616, in run_until_complete
return future.result()
File "C:UsersintelAppDataLocalProgramsPythonPython38libsite-packagesrequests_html.py", line 512, in _async_render
await page.goto(url, options={'timeout': int(timeout * 1000)})
File "C:UsersintelAppDataLocalProgramsPythonPython38libsite-packagespyppeteerpage.py", line 885, in goto
raise error
pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 8000 ms exceeded.
[Finished in 13.0s with exit code 1]
[shell_cmd: python -u "C:UsersintelDesktophackerrank.py"]
[dir: C:UsersintelDesktop]
[path: C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Filesnodejs;C:Python38;C:UsersintelAppDataLocalProgramsPythonPython38Scripts;C:UsersintelAppDataLocalProgramsPythonPython38;C:MinGWbin;C:UsersintelAppDataLocalProgramsMicrosoft VS Codebin]
Я увидел комментарий к одному из моих постов и увидел ответы других людей, чтобы повторно запустить его, тогда он будет работать. Я не понимаю, почему…
Ответ №1:
Ошибка, которую вы получаете, предполагает, что вы не получаете ответ от сервера своевременно.
Я успешно запустил ваш код на своем компьютере (Ubuntu 18.04) и получил следующие результаты:
Seven Days -Between Life And Death
Have you ever encountered a fake friend? If So, Try These Simple Tips To Overcome it.
Does Anybody Ever Wonder Why He’s My Everything?
Ladies, Why Should You Treat Your Face Like The Coloring Books?
Listen, Girl, Aren’t You Curious How The Last Line Could Be This Hurtful?
The girl name “Rich”
She Lost Her Beloved Mother, But Why She Asserted that Loss Was Not Just A Loss sometimes?
You Used To Try This Lonely. Have You Ever Imagine The flavor You Tried To Eat it with Your Lover?
If You Have Siblings, You Won’t Comprehend this. Have You Ever Wonder How A Child Feels Like? This Is How It Perceives.
Is It Okay To Help A Stranger?
The Nightmare Was Always Considered A Bad Omen, But It Turned Incredible Differently.
If You’re A Woman Or Girl Who Loves To Wear Lipstick, Read This Poetry.
She Wants To Spread This Poetry For Every Girl Or Woman That Was Born Just Like The Way She Was.
Вы должны проверить свое подключение к Интернету.
В качестве альтернативы я бы посоветовал вам запустить idle в режиме администратора и повторно запустить ваш код idle
.