Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 硒美素素素素罐头';无法获取所有HTML内容_Python_Html_Selenium_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 硒美素素素素罐头';无法获取所有HTML内容

Python 硒美素素素素罐头';无法获取所有HTML内容,python,html,selenium,web-scraping,beautifulsoup,Python,Html,Selenium,Web Scraping,Beautifulsoup,我正在刮桌子底部的标签“容量:操作可用-晚上” 我可以得到所有的HTML,当我打印HTML时,所有的东西都会显示出来,但是当我发出命令查找我需要的特定信息时,解析器找不到它 这是我的剧本: cc_driver = webdriver.Chrome('/Users/.../Desktop/chromedriver') cc_driver.get('https://lngconnection.cheniere.com/#/ccpl') cc_html = cc_driver.page_source

我正在刮桌子底部的标签“容量:操作可用-晚上”

我可以得到所有的HTML,当我打印HTML时,所有的东西都会显示出来,但是当我发出命令查找我需要的特定信息时,解析器找不到它

这是我的剧本:

cc_driver = webdriver.Chrome('/Users/.../Desktop/chromedriver')
cc_driver.get('https://lngconnection.cheniere.com/#/ccpl')
cc_html = cc_driver.page_source

cc_content = soup(cc_html, 'html.parser')
cc_driver.close()
cc_table = cc_content.find('table', class_='k-selectable')
#print(cc_content.prettify())
print(cc_table.prettify())
现在当我做这个

print(cc_table.prettify())

输出是除实际表数据之外的所有数据。我的代码或HTML中是否存在隐藏实际表值的错误?当我在页面上打印Selenium捕获的所有内容时,我就能看到它。HTML也没有任何单元格值的特定ID标记。

您正在查看尚未完成的HTML。所有元素还没有从javascript返回。所以你可以做一个webdriver等等

from selenium import webdriver
from bs4 import BeautifulSoup as soup
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

cc_driver = webdriver.Chrome(r"path for driver")
cc_driver.get('https://lngconnection.cheniere.com/#/ccpl')
WebDriverWait(cc_driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 
'#capacityGrid > table > tbody')))
cc_html = cc_driver.page_source

cc_content = soup(cc_html, 'html.parser')
cc_driver.close()
cc_table = cc_content.find('table', class_='k-selectable')
#print(cc_content.prettify())
print(cc_table.prettify())

这将等待元素出现。

这将帮助您获取表格html

from selenium import webdriver
from bs4 import BeautifulSoup as bs

cc_driver = webdriver.Chrome('../chromedriver_win32/chromedriver.exe')
cc_driver.get('https://lngconnection.cheniere.com/#/ccpl')
cc_html = cc_driver.page_source

cc_content = bs(cc_html, 'html.parser')
cc_driver.close()
cc_table = cc_content.find('table', attrs={'class':'k-selectable'})

#print(cc_content.prettify())
print(cc_table.prettify())

非常感谢你。这是有效的,我不知道如何添加等待。我必须通过XPATH而不是CSS_选择器来查找,但这是一个相同的方法,谢谢Mohammed brother