0

I am trying to get whole text but they do not give a whole text is there any solution for that kindly recommend me these is the page link https://www.askgamblers.com/online-casinos/reviews/casino-friday

enter image description here

this is code:

from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
import pandas as pd
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import pandas as pd
from csv import writer


options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1920x1080")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
wait = WebDriverWait(driver, 10)

url = "https://www.askgamblers.com/online-casinos/reviews/casino-friday"        
driver.get(url)
key=[]
value=[]


pays =driver.find_element(By.XPATH,"//h2[text()[contains(.,'Virtual Games')]]/following-sibling::p").text
print(pays)
Amen Aziz
  • 153
  • 6
  • It's a guess, but do you want to use `driver.find_elements` instead of `driver.find_element` so that all paragraphs can be found and returned? – Raketenolli Dec 08 '22 at 20:14
  • it give me all paragraph in page but I want only paragraph of `Virtual Games` only – Amen Aziz Dec 08 '22 at 20:17
  • You mean only the heading that says "Virtual Games", only the immediately following paragraph "The casino boasts ..." or all five following paragraphs before the next heading. What exactly are you getting? – Raketenolli Dec 08 '22 at 20:30
  • yes I get all the paragraph before next heading ......when I use driver.find_elements it give all paragraph in the page or when I use driver.find_element it give me these line only(The casino boasts a vast offer of slots, video poker games and table games.) – Amen Aziz Dec 08 '22 at 20:36
  • Does this answer your question? [XPath : select all following siblings until another sibling](https://stackoverflow.com/questions/2161766/xpath-select-all-following-siblings-until-another-sibling) – Raketenolli Dec 08 '22 at 20:39
  • Itry that but not work .....//h2[text()[contains(.,'Virtual Games')]]/following-sibling::p[following::h2] – Amen Aziz Dec 08 '22 at 20:53
  • You have to specify the exact `h2`, e.g. through the title, otherwise it'll select all `p`s that are followed by some `h2`, which is of course true for more paragraphs in the article than just the ones you are interested in. – Raketenolli Dec 09 '22 at 19:05

1 Answers1

0

You can try this:

# to handle cookie information
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".btn.btn--yellow.policy-accept"))).click()

heading_1 = driver.find_element(By.CSS_SELECTOR, ".review-text.richtext h2")
heading_1.location_once_scrolled_into_view
time.sleep(1)

# to print the title
paragraph_title = driver.find_element(By.XPATH, ".//*[@class='review-text richtext']/h2[2]").text
print(paragraph_title)


for i in range(3, 8):
    print(driver.find_element(By.XPATH, ".//*[@class='review-text richtext']/p[" + str(i) + "]").text)
    print()

Those 'Virtual Games' paragraphs are not under the separate parent, the parent tag <section class="review-text richtext" is common for all the paragraphs on that page, so you have to use the index in XPath as in the for loop.

If any of the paragraphs are added or removed in the future then you have to change that index in for loop.

Output:

Virtual Games
The casino boasts a vast offer of slots, video poker games and table games.

Casino Friday doesn’t differ from the rest of casinos in terms of video slots offered. This is the largest section on their website and navigating through it is made easy due to attractive lobby design. Players can look up the slots of their choice by using the search bar or filter slots per software providers. Bettors’ favourites such as Dead or Alive Slot, Book of Oz or Leprechaun’s Lucky Barrel from the likes of NetEnt, Microgaming and Booming Games are all there.

The lobby also features a handy menu of the most popular titles categorized by theme or special features such as sticky wild symbols, such as The Good The Bad and The Ugly or Thunder Cash slots.

Table games fans will enjoy this casino, too: roulette, blackjack and baccarat are all there. Numerous iterations of these popular table games are also grouped per aforementioned categories for an easier wayfinding. All it takes is jumping to the preferred category, say Blackjack, and you’ll find other versions of the game there, including Atlantic City Blackjack or European Blackjack Gold.

Video poker games section is somewhat limited but the famous classics are all there: Deuces Wild, Jacks or Better or All Aces, to mention a few.
AbiSaran
  • 2,538
  • 3
  • 9
  • 15