selenium 给予错误

wko9yo5t  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(119)
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


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)

product=[]
soup = BeautifulSoup(driver.page_source,"lxml")

responsibles=soup.select("div#tabResponsible")

for responsible in responsibles:
    t1=responsible.select_one(".icon-deposit-limit-tool+ span")
    if "<span class="">Deposit Limit Tool</span>" in t1:
        print("yes")
    elif "<span class='strikethrough'>Deposit Limit Tool</span>" in t1:
        print("no")

我希望我的输出在yes or no,但每次他们给予我no,如果有no line,那么他们打印是,否则他们打印没有as you see in pic请希望我做错了,你建议我的解决方案,这些是页面链接https://www.askgamblers.com/online-casinos/reviews/casino-friday

x4shl7ld

x4shl7ld1#

完整代码

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

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, 20)

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

soup = BeautifulSoup(driver.page_source, "html.parser")

responsibles = soup.find("div", {"id": "tabResponsible"})
responsibles = responsibles.find_all("div", {"class": "review-details__item"})
Title = []
Value = []
for i in responsibles:
    if (i.find("span", {"class": "strikethrough"})):
        Title.append(i.find("span").text.strip())
        Value.append("No")
        print(i.find("span").text.strip(), ": ", "No")
    else:
        Title.append(i.find("span").text.strip())
        Value.append("Yes")
        print(i.find("span").text.strip(), ": ", "Yes")
# dictionary of lists to Dataframe
mydict = {'Title': Title, 'Value': Value, }
df = pd.DataFrame(mydict)

# saving the dataframe
df.to_csv('output.csv')
print(df)

输出

Deposit Limit Tool :  Yes
Wager Limit Tool :  No
Loss Limit Tool :  No
Time/Session Limit Tool :  No
Self-Exclusion Tool :  Yes
Cool Off/Time-Out Tool :  Yes
Reality Check Tool :  No
Self-Assessment Test :  Yes
Withdrawal Lock :  No
Self-Exclusion Register Participation :  Yes
                                   Title Value        
0                     Deposit Limit Tool   Yes        
1                       Wager Limit Tool    No        
2                        Loss Limit Tool    No        
3                Time/Session Limit Tool    No        
4                    Self-Exclusion Tool   Yes        
5                 Cool Off/Time-Out Tool   Yes        
6                     Reality Check Tool    No        
7                   Self-Assessment Test   Yes        
8                        Withdrawal Lock    No        
9  Self-Exclusion Register Participation   Yes

希望这对你有帮助。快乐编码:)

相关问题