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)
soup = BeautifulSoup(driver.page_source, "html.parser")
product = []
pays=soup.select("div#tabPayments")
for pay in pays:
try:
t4=pay.select_one(" .review-details-wrapper+ .review-details-wrapper .review-details__item:nth-child(2) .review-details__text")
t4 = [i for i in t4 if i.text]
except:
pass
supports = soup.find("div", {"id": "tabCustomers"})
supports = supports.find("div", {"class": "review-details__text"})
email = "Support Email:"+supports.text.replace("\n", "").split(":")[1]
print(email)
他们给我看了这样输出
['\nSupport\nEmail:\nsupport@casinofriday.com\n', '\n']
但我希望输出是这样的:
Support Email:support@casinofriday.com
我想从我的字符串中删除所有不需要的字符,请推荐任何解决方案,这些是页面链接https://www.askgamblers.com/online-casinos/reviews/casino-friday
3条答案
按热度按时间icnyk63a1#
完整代码
输出
希望这对你有帮助。快乐编码:)
esbemjvw2#
看起来你可以利用两种方法来实现你的目标:replace()和split(),然后再追加。
mpgws1up3#
您可以使用
.replace()
方法删除字符串中任何不需要的字符,将不需要的字符替换为空字符串。假设结果字符串存储在
product
string中,那么,要删除不需要的[
符号,可以这样做:对所有要删除的字符执行此操作将导致以下代码:
最后的
strip()
会移除开头和结尾的空格。