Issue
I want to get text after a specific text using beautiful soup. This website https://www.capterra.ca/reviews/203084/voip-ms has customer reviews and I want to extract only the "pros:" section for the reviews and copy it to a text file titled "pros" instead of all the text.
import requests,bs4 res = requests.get('https://www.capterra.ca/reviews/203084/voip-ms')
parseSoup= bs4.BeautifulSoup(res.text,'html.parser')
paragraphs = parseSoup.find_all('p')
with open("web.txt", 'w') as file:
for paragraph in paragraphs:
file.write(paragraph.get_text() + "\n")
This is my code so far that just copies all the text into a text file.
Solution
You can use CSS selector p:-soup-contains("Pros:") + p
(This will search for all direct <p>
siblings of <p>
tags containing string "Pros:"):
import requests
from bs4 import BeautifulSoup
res = requests.get("https://www.capterra.ca/reviews/203084/voip-ms")
soup = BeautifulSoup(res.text, "html.parser")
for t in soup.select('p:-soup-contains("Pros:") + p'):
print(t.get_text(strip=True))
print('-' * 80)
Prints:
It's a cut and dry VoIP service that provides exactly what I need, how I need without burdensome interfaces.
--------------------------------------------------------------------------------
If you know what you are doing this offers great value for money. An initial challenge is working out the per minute pricing model for voip services. However, it is invariably way cheaper than any other phone model.
--------------------------------------------------------------------------------
Many features but simply it just works. A great value.
--------------------------------------------------------------------------------
It is a powerful software that gives lots of options and functionality with VOIP. It is lean and does not have a lots of bulk so it can be used over phone lines without using lots of bandwidth. The wiki is helpful and the customer service has always been willing to help. It is great that you don't need to purchase customized equipment to use VOIP.ms. Now with the self isolation it has been great to have the option to forward the phone numbers.
--------------------------------------------------------------------------------
Like me, you'll be amazed at the range of features you get for the vastly reduced price when comparing the service to that of a traditional telephone service. Once you learn the admin interface of voip.ms, you'll find it simple to set up an auto attendant for routing calls within your business. You'll love the ability to forward a voice mail message to your e-mail address, with the message attached as an mp3 file. Many more options for call routing are offered, such as hunting.
--------------------------------------------------------------------------------
...
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.