Python Forum
Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup
#1
Hi guys,

How's it going?

I've been in weeks trying to remove a double-quote (") from a word (as I want to count the word in a certain text or webpage and what not).

Been going back and forth in changing the variable to list or string in order to use their methods.

Here's my code:

import requests
from bs4 import BeautifulSoup

url = 'https://burniva.com/sam-smith-weight-loss/'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')

articles = soup.find('div', class_="cmsmasters_text")
paragraphs = articles.find_all('p')

new_p = []
for p in paragraphs:
    new_p.append(p.get_text())

for p in new_p:
    print(str(p).lstrip('"'))
There would be words like:
“Stay with Me” and “I’m not the Only One”,
"Latch"
“The Thrill of It All”
“Oh! Carol”
etc. etc....

I cannot remove those double-quotes. Tried .replace, .strip, even if I .split them up or turn them into a list. I can remove other special characters like punctuation, apostrophe, period, etc. etc.... but never the double-quotes.

Pls. try the code and you'll get the output of all the article including those that I had mentioned.

Hope someone can help me as I am now very interested to what I am missing, to why I cannot remove them and have a clean list of only just words.

Thanks in advance!
Reply


Messages In This Thread
Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup - by soothsayerpg - Oct-22-2019, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove gilberishs from a "string" kucingkembar 2 350 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  Retrieve word from string knob 4 588 Jan-22-2024, 06:40 PM
Last Post: Pedroski55
  extract substring from a string before a word !! evilcode1 3 633 Nov-08-2023, 12:18 AM
Last Post: evilcode1
  Need help on how to include single quotes on data of variable string hani_hms 5 2,224 Jan-10-2023, 11:26 AM
Last Post: codinglearner
Smile please help me remove error for string.strip() jamie_01 3 1,284 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,595 Sep-03-2022, 11:21 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,173 Aug-19-2022, 08:07 PM
Last Post: Winfried
  Remove a space between a string and variable in print sie 5 1,894 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,248 Jul-20-2022, 09:05 AM
Last Post: arbiel
  How do I remove spurious "." from a string? Zuhan 7 2,184 Apr-12-2022, 02:06 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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