无法使用bs4、python和selenium获取详细信息
我正在使用下面的代码打印soup变量,它只是页面的源代码 代码无法使用bs4、python和selenium获取详细信息,python,selenium,web-scraping,beautifulsoup,python-requests,Python,Selenium,Web Scraping,Beautifulsoup,Python Requests,我正在使用下面的代码打印soup变量,它只是页面的源代码 代码 from urllib.request import urlopen from bs4 import BeautifulSoup import json, requests, re, sys from selenium import webdriver import re, time yes_url = "https://www.yesbank.in/personal-banking/yes-first/cards/c
from urllib.request import urlopen
from bs4 import BeautifulSoup
import json, requests, re, sys
from selenium import webdriver
import re, time
yes_url = "https://www.yesbank.in/personal-banking/yes-first/cards/credit-card/yes-first-exclusive-credit-card"
driver = webdriver.Chrome(executable_path="C:\\Users\\Hari\\Downloads\\chromedriver.exe")
driver.get(yes_url)
time.sleep(3)
# r = requests.get(yes_url)
soup = BeautifulSoup(driver.page_source, 'lxml')
print(soup)
driver.close()
我从中抓取页面源的链接是:
运行上述代码后,代码一直运行到数小时,但我没有得到输出
请帮助我抓取页面源代码,以便在运行代码后获得一些输出。问题:您正在处理的是一个现代网站,它会检查浏览器本身是否受控制或未使用健壮的浏览器 如何做到这一点 只需打开浏览器控制台,然后键入以下内容:
navigator.webdriver
如果是false
,那么您的浏览器就不会受到任何健壮的程序(如selenium
)的控制
如果它是真的
,那么它是受控的
在您的情况下,您必须禁用它以欺骗网站检查机制
以下是您可以实现的目标:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
from bs4 import BeautifulSoup
options = Options()
options.headless = True
options.set_preference("dom.webdriver.enabled", False)
driver = webdriver.Firefox(options=options)
driver.get('https://www.yesbank.in/personal-banking/yes-first/cards/credit-card/yes-first-exclusive-credit-card')
try:
element = WebDriverWait(driver, 10).until(
EC.title_contains('YES'))
soup = BeautifulSoup(driver.page_source, 'lxml')
print(soup.prettify())
finally:
driver.quit()
我得到的结果是:访问被拒绝您没有访问权限“”在这台服务器上。@Rocket Nikita所以我需要一种方法来绕过它,并能够访问页面的源代码。你能告诉我们你想刮取页面的哪一部分吗?@bilakos我想刮取该页面中福利选项卡的详细信息。@MaredpallyJalebi好的,我要试试@αԋɱҽԃєιcαη我能在chrome上做同样的事情吗浏览器?是的!选项。添加_参数('--disable blink features=AutomationControlled')@aԋɱҽԃαМєιcαη你能为同一个参数编写代码吗。