【发布时间】:2021-11-12 07:08:48
【问题描述】:
我正在尝试使用以下代码简化我的财务数据收集。但是,它似乎有几个问题。我想抓取以下页面以获取特定的 href:'https://www.witan.com/investor-information/factsheets/#currentPage=1'
我试图解析的 href: href="/media/1767/witan-investment-trust_factsheet_310821.pdf"
目前我正在使用 selenium 来执行此操作,但是它有点慢,所以如果可以使用 BS4 进行抓取,我愿意提供建议 - 我的尝试到目前为止都失败了。
# Set options for selenium
options = Options()
options.headless = True
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_argument("--window-size=1920,1200")
# Requests website using Selenium & ChromeDriver
driver = webdriver.Chrome('C:/AnaConda/chromedriver.exe', options=options)
driver.get('https://www.witan.com/investor-information/factsheets/#currentPage=1') # Requests website
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")
link_finder = soup.findAll('a', href=re.compile('/witan-investment-trust-factsheet'))[0]
当使用上面的代码时,我得到: class="ico-arrow document-view size" href="/media/1750/witan-investment-trust-factsheet-30jun2021.pdf" target="_blank"...
希望有人可以帮助我!
【问题讨论】:
标签: selenium web-scraping beautifulsoup