我有一個問題,從這個鏈接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