python - 无法弄清楚如何使用/selenium 抓取页面

标签 python selenium web-scraping

我知道如何到达我想通过 Selenium 抓取的结果页面,但我不知道如何实际抓取结果页面。我也尝试过机械化,但这并没有让我走得更远。这就是我现在所在的位置:

import re
import urllib2
import csv
import os
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup, SoupStrainer
import datetime
import time
import smtplib
import atexit
import signal
import json
import os
import gspread
import sys
import gc

script_path = os.path.dirname(os.path.realpath(__file__))

driver = webdriver.PhantomJS(executable_path="/usr/bin/phantomjs", service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])

#launches headless browser, completes proper search in Casenet
def main():

    driver.get('https://www.courts.mo.gov/casenet/cases/nameSearch.do')

    if 'Service Unavailable' in driver.page_source:
        log('Casenet website seems to be down. Receiving "service unavailable"')
        driver.quit()
        gc.collect()
        return False

    court = Select(driver.find_element_by_id('courtId'))

    court.select_by_visible_text('All Participating Courts')

    case_enter = driver.find_element_by_id('inputVO.lastName')

    case_enter.send_keys('Wakefield & Associates')

    driver.find_element_by_id('findButton').click()

    time.sleep(1)

    number_of_pages = 204

    for i in range(number_of_pages):

        output_trs = []

        party = (driver.find_element_by_class_name('outerTable'))

        output_trs.append(party)

        print output_trs

main()

最终的想法是将当事人、案件编号和归档日期作为字符串存储在 .csv 中。当我现在打印output_trs时,我得到:

selenium.webdriver.remote.webelement.WebElement (session="c4e7b9e0-7a3b-11e8-83f2-b9030062270d", element=":wdc:1530125781332")

感谢任何帮助。

最佳答案

您正在尝试打印 Web 元素对象 rather than its text content .

打印文本内容的一种方法(注意编码):

for content in output_trs:
    print content.text

关于python - 无法弄清楚如何使用/selenium 抓取页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51069749/

相关文章:

python - python3中有没有办法检查不止一件事?

selenium - xpath:查找具有属性并且包含的​​元素?

javascript - 尝试使用 cucumber.js 实现页面对象模型时出错

java - 如何单击具有输入类型和值的按钮?

java - 为什么 Selenium Webdriver 找不到某些 css 选择器?

python - 在 Django 中,当我运行 migrate 时,出现错误 : accounts_userinfo. user_id may not be NULL

python - 有向图中的最大公共(public)子图

python - Pandas 合并101

python - PyPDF2 无法读取非英文字符,在 extractText() 上返回空字符串

java - 如何从Java Web应用程序中提取数据?