【发布时间】:2015-04-16 19:21:32
【问题描述】:
我写了一个简单的爬虫程序来爬取“http://fortune.com/fortune500/”,想获取<option value = "...">...</option>的值,但是使用webelement.text获取带有标签名(“option”)的内容时,什么都没有显示.我想知道为什么?谁能帮我解决这个问题?
# -*- coding: utf-8 -*-
import mechanize
from bs4 import BeautifulSoup
import re
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
#-----------selenium part(ignored)----------------#
browser = webdriver.Chrome() # Get local session of firefox
browser.get("http://fortune.com/fortune500/")
time.sleep(1) # Let the page load, will be added to the API
industry_button = browser.find_element_by_name('filters[Industry]')
print industry_button
count = 0;
industry_value = industry_button.find_elements_by_tag_name('option')
for number in industry_value:
count += 1
print number
print count
【问题讨论】:
标签: python firefox selenium selenium-webdriver