Answer the question
In order to leave comments, you need to log in
How to use regex to translate (googletrans) the desired part of a string in Python?
Can't embed regex and translate headers in response without affecting project name
Regular expression itself:
(?<=\w+: ).+(?=)
Generated code for Python:
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question