测试积点老人 发表于 2021-12-27 11:44:37

selenium和PhantomJS的配合使用!

selenium和PhantomJS的配合使用:AttributeError: module 'selenium.webdriver' has no attribute 'PhantomJS'
from selenium import webdriver
import time
import csv
import pymongo
client = pymongo.MongoClient('localhost', 27017)
mydb = client['mydb']
qq_shuo = mydb['qq_shuo']
driver = webdriver.PhantomJS()
driver.maximize_window()
def get_info(qq):
    driver.get('http://user.qzone.qq.com/{}/311'.format(qq))
    driver.implicitly_wait(10)
    try:
      driver.find_element_by_id('login_div')
      a = True
    except:
      a = False
    if a == True:
      driver.switch_to.frame('login_frame')
      driver.find_element_by_id('switcher_plogin').click()
      driver.find_element_by_id('u').clear()
      driver.find_element_by_id('u').send_keys('账号')
      driver.find_element_by_id('p').clear()
      driver.find_element_by_id('p').send_keys('密码')
      driver.find_element_by_id('login_button').click()
      time.sleep(3)
    driver.implicitly_wait(3)
    try:
      driver.find_element_by_id('QM_OwnerInfo_Icon')
      b = True
    except:
      b = False
    if b == True:
      driver.switch_to.frame('app_canvas_frame')
      contents = driver.find_elements_by_css_selector('.content')
      times = driver.find_elements_by_css_selector('.c_tx.c_tx3.goDetail')
      for content, tim in zip(contents, times):
            data = {
                'time': tim.text,
                'content': content.text
            }
            qq_shuo.insert_one(data)
if __name__ == '__main__':
    qq_lists = []
    fp = open('C:/Users/LP/Desktop/QQmail.csv')
    reader = csv.DictReader(fp)
    for row in reader:
      qq_lists.append(row['电子邮件'].split('@'))
    fp.close()
    for item in qq_lists:
      get_info(item)运行结果及报错内容

"D:\Program Files (x86)\Anaconda3\python.exe" E:/python/从零开始学Python网络爬虫_源代码/qq_kongjian.py
Traceback (most recent call last):
File "E:/python/从零开始学Python网络爬虫_源代码/qq_kongjian.py", line 10, in <module>
    driver = webdriver.PhantomJS(executable_path=r'D:\Program Files (x86)\phantomjs-2.1.1-windows\bin\phantomjs.exe')
AttributeError: module 'selenium.webdriver' has no attribute 'PhantomJS'
Process finished with exit code 1
我的解答思路和尝试过的方法

driver = webdriver.PhantomJS(executable_path=r'D:\Program Files (x86)\phantomjs-2.1.1-windows\bin\phantomjs.exe')




qqq911 发表于 2021-12-28 10:24:21

需要安装对应插件

郭小贱 发表于 2021-12-28 15:44:17

这块没搞过...学习下。

jingzizx 发表于 2021-12-28 18:54:31

:Q
页: [1]
查看完整版本: selenium和PhantomJS的配合使用!