import re
pattern = re.compile(ur'(?<=\w+: ).+(?=)')
str = u''
print(pattern.search(str))from bs4 import BeautifulSoup
import requests
from googletrans import Translator
import re
x = 0
while True:
if x == 0:
url = "https://news.ycombinator.com/newest"
else:
url = "https://news.ycombinator.com/newest" + nexx
request = requests.get(url)
soup = BeautifulSoup(request.text, "html.parser")
teme = soup.find_all("td", class_="title")
for temes in teme:
temes = temes.find("a", {'class' : 'titlelink'})
if temes is not None and 'github.com' in str(temes):
sublink = temes.get('href')
print(str(temes.text) + ' ' + str(sublink))
print('===')
nex = soup.find(class_ = 'morelink')
nexlink = nex.get('href')
nexx = nexlink[6:]
x += 1 if temes is not None and 'github.com' in str(temes):
sublink = temes.get('href')
print(str(temes.text) + ' ' + str(sublink))
print('===')if temes is not None and 'github.com' in str(temes):
sublink = temes.get('href')
m = temes.text.split(': ', 1)
if len(m) == 2:
translation = translator.translate(m[1], dest='ru', src='en')
print(m[0] + ': ' + translation.text + ' ' + sublink)
print('===')if temes is not None and 'github.com' in str(temes):
sublink = temes.get('href')
m = re.search('^(.+?: )(.+)', temes.text)
if m:
translation = translator.translate(m.group(2), dest='ru', src='en')
print(m.group(1) + translation.text + ' ' + sublink)
print('===') for temes in teme:
temes = temes.find("a", {'class' : 'titlelink'})
if temes is not None and 'github.com' in str(temes):
sublink = temes.get('href')
m = temes.text.split(': ', 1)
if len(m) == 2:
translator = Translator()
translation = translator.translate(m[1], dest='ru', src='en')
print(m[0] + ': ' + translation.text + ' ' + sublink)
print('===')Traceback (most recent call last):
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\parsing_HackerNews.py", line 24, in <module>
translation = translator.translate(m[1], dest='ru', src='en')
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\venv\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\venv\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\venv\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\venv\lib\site-packages\googletrans\gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group' pip install googletrans==4.0.0-rc1 AttributeError: 'NoneType' object has no attribute 'get' ? Я так понимаю причина в том что в определенный момент nex возвращает None у которого нет метода .get , пытался пофиксить с помощьюif nex == 'None':
continueShow HN: Сервер TCP и HTTP, WebSocket и UDP Echo для всех ваших нужд https://github.com/asad-awadia/echo-server
===
Show HN: MdSilo Desktop, наименьшее хранилище местных знаний на вашем рабочем столе https://github.com/danloh/mdSilo-app/releases
===
Show HN: Создавайте и отправляйте несколько образов Docker из монорепозитория. https://github.com/vitorfhc/bob
===
Show HN: QjsIpc, вызов процедуры JavaScript в dotnet с помощью QuickJS и wasmtime https://github.com/iwate/qjsipc
===
Thefuck: Великолепное приложение, которое исправляет вашу предыдущую консольную команду https://github.com/nvbn/thefuck
===
Show HN: Safe-node — PoC узла с запросами разрешений а-ля Deno https://github.com/stagas/safe-node
===
Show HN: Найдите приложения для Mac, которые можно заменить версией Mac App Store https://github.com/rwv/AppStorify
===
Snappass: Делитесь паролями безопасно https://github.com/pinterest/snappass
===
Traceback (most recent call last):
File "C:\Users\Rubi\PycharmProjects\parsing_HackerNews\parsing_HackerNews.py", line 32, in <module>
nexlink = nex.get('href')
AttributeError: 'NoneType' object has no attribute 'get'
Process finished with exit code 1