我有一个问题,从这个链接Python的phantomjs加载网页不正确
提取带给我从这个链接,而不是它本身的主要页面的数据。 http://www.bursamalaysia.com/market/listed-companies/company-announcements/#/?category=all
任何想法为什么发生这种情况? 我使用PhantomJS硒和美丽的汤来帮助我。
# The standard library modules
import os
import sys
import re
import sqlite3
import locale
# The wget module
import wget
import time
import calendar
from datetime import datetime
# The BeautifulSoup module
from bs4 import BeautifulSoup
# The selenium module
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
def getURLS(url):
driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
driver.get(url) # load the web page
src = driver.page_source
#Get text and split it
soup = BeautifulSoup(src, 'html5lib')
print soup
link ='http://www.bursamalaysia.com/market/listed-companies/company-announcements/#/?category=FA&sub_category=FA1&alphabetical=All&company=5250'
getURLS(link)
亚历克斯Lucaci解决方案
def getURLS(url):
driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
driver.get(url) # load the web page
src = driver.page_source
category_select = Select(driver.find_element_by_xpath('//*[@id="bm_announcement_types"]'))
category_select.select_by_visible_text("Financial Results")
category_select2 = Select(driver.find_element_by_xpath('//*[@id="bm_sub_announcement_types"]'))
category_select2.select_by_visible_text("Financial Results")
category_select3 = Select(driver.find_element_by_xpath('//*[@id="bm_company_list"]'))
category_select3.select_by_visible_text("7-ELEVEN MALAYSIA HOLDINGS BERHAD (5250)")
driver.find_element_by_xpath('//*[@id="bm_company_announcements_search_form"]/input[1]').click()
src = driver.page_source
soup = BeautifulSoup(src, 'html5lib')
link="http://www.bursamalaysia.com/market/listed-companies/company-announcements/#/?category=all"
getURLS(link)
嘿,对不起伙伴。我测试了它并将汤打印出来。它仍然显示来自主页面的数据而不是过滤的值。有什么办法让它通过它的下拉选择值呢? – Napmi
我编辑了我的第一篇文章。看一看。 –
谢谢队友!在Google上搜索如何点击提交以及在find_element_by_xpath上找到的新知识,并且它很有用!非常感谢! – Napmi