Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex multi-line
#7
(Aug-27-2022, 09:53 PM)snippsat Wrote:
(Aug-27-2022, 08:54 PM)kucingkembar Wrote: it will nice to get that regex that can be use
Regex and Html are not best friends the classics post🌞 that never get old.

I would do it like this.
import requests
from bs4 import BeautifulSoup
# pip install html2text
import html2text

url = 'https://lightnovelstranslations.com/the-galactic-navy-officer-becomes-an-adventurer/chapter-95-preparations-for-departure-part-4/'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
story = soup.select_one('#post-104395 > div')
text_maker = html2text.HTML2Text()
text_maker.ignore_links = True
text = text_maker.handle(story.prettify())
print(text) 
Output:
Chapter 95 - Preparations for Departure Part 3 * * * **Translator: SFBaka** **Editor: Thor’s Stone** * * * –Roberto’s POV– The princess and Alan-sama welcomed our arrival at the royal capital with more enthusiasm than I expected. I’m glad I prepared myself beforehand to get scolded for arbitrarily departing with an advanced party. It was already late at night, and most of the others have returned to their rooms. But some of the leaders including Adjutant Dalshim still remained in the hall to talk more with me. “So how is it? What is your impression of serving under Alan-sama, Dalshim- dono?” “In a word, splendid. I can declare without any qualms that everything we’ve accomplished so far was largely due to Alan-sama’s contributions.” .....

Regex and Html are not best friends the classics post🌞 that never get old.
i read that link before, the solution is about,
sorry if external question, what is this "Have you tried using an XML parser instead?"
any link to it?
anyway your code work, I add reputation point again for you and another one who replies
Reply


Messages In This Thread
regex multi-line - by kucingkembar - Aug-27-2022, 05:11 PM
RE: regex multi-line - by Gribouillis - Aug-27-2022, 05:25 PM
RE: regex multi-line - by kucingkembar - Aug-27-2022, 05:37 PM
RE: regex multi-line - by Gribouillis - Aug-27-2022, 08:36 PM
RE: regex multi-line - by kucingkembar - Aug-27-2022, 08:54 PM
RE: regex multi-line - by snippsat - Aug-27-2022, 09:53 PM
RE: regex multi-line - by kucingkembar - Aug-27-2022, 10:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 2 1,354 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 1,868 May-23-2024, 03:02 PM
Last Post: deanhystad
  multi-line CMD in one-line python kucingkembar 5 6,144 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  [SOLVED] Why does regex fail cleaning line? Winfried 5 3,523 Aug-22-2021, 06:59 PM
Last Post: Winfried
  Multi-line console input lizze 4 3,592 Dec-26-2020, 08:10 AM
Last Post: lizze
  Regex on more than one line ? JohnnyCoffee 3 3,478 Mar-12-2020, 02:01 PM
Last Post: JohnnyCoffee
  Regex won't replace character with line break Tomf96 2 3,418 Jan-12-2020, 12:14 PM
Last Post: Tomf96
  Python convert multi line into single line formatted string karthidec 2 11,524 Dec-23-2019, 12:46 PM
Last Post: karthidec
  multi-line messages in raised exceptions? Skaperen 3 9,337 Aug-01-2019, 02:17 AM
Last Post: Skaperen
  Do I always have to use triple quotes or \n for multi-line statements? DragonG 3 3,457 Oct-24-2018, 11:21 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020