@Weishaupt

Как с помощью regex перевести(googletrans) нужную часть строки в Python?

Не получаеться встроить регулярку и перевести заголовки в ответе не затрагивая название проекта

Сама регулярка:
(?<=\w+: ).+(?=)

Сгенерированный код для Python:
import re
pattern = re.compile(ur'(?<=\w+: ).+(?=)')
str = u''
print(pattern.search(str))


Немного о googletrans:
translate(text, dest='ru', src='en')
text - Исходный текст для перевода.
src - Язык исходного текста
dest - Язык для перевода исходного текста.

Исходники:
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
  • Вопрос задан
  • 131 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы