如何提取安全ID、安全代码、组/索引的值,平均Wtd价格,交易日期,交易数量,可交付数量的百分比,使用Python3将其保存到XLS文件中。下面是链接。在
https://www.bseindia.com/stock-share-price/smartlink-network-systems-ltd/smartlink/532419/
附言:我对python完全陌生。我知道很少有libs能让报废变得更容易,比如beauthoulsoup、selenium、requires、lxml等等,对它们没有太多的了解。在
编辑1: 我试过了
from bs4 import BeautifulSoup
import requests
URL = 'https://www.bseindia.com/stock-share-price/smartlink-network-systems-ltd/smartlink/532419/'
r = requests.get(URL)
soup = BeautifulSoup(r.content, 'html5lib')
table = soup.find('div', attrs = {'id':'newheaddivgrey'})
print(table)
它的输出是None
。我期待网页中的所有表格,并进一步过滤,以获得所需的数据。在
尝试了另一个代码。同样的问题。在
编辑2: 试过硒。但我没有拿到表上的东西。在
from selenium import webdriver
driver = webdriver.Chrome(r"C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\bin\chromedriver.exe")
driver.get('https://www.bseindia.com/stock-share-price/smartlink-network-systems-ltd/smartlink/532419/')
table=driver.find_elements_by_xpath('//*[@id="SecuritywiseDeliveryPosition"]/table/tbody/tr/td/table/tbody/tr[1]/td')
print(table)
driver.quit()
输出是[<selenium.webdriver.remote.webelement.WebElement (session="befdd4f01e6152942c9cfc7c563a6bf2", element="0.13124528538297953-1")>]
在用Selenium加载页面后,可以使用
driver.page_source
获得Javascript修改的页面源代码。然后您可以在beauthoulGroup对象中传递这个页面源代码。在这段代码将为您提供
table
变量中的Securitywise Delivery Position表。然后,您可以解析这个BeautifulSoup对象以获得所需的不同值。在soup
对象包含包含动态添加的元素的整页源。现在,您可以解析它来获得您提到的所有内容。在相关问题 更多 >
编程相关推荐