窝在家里写程序 发表于 2020-8-20 16:54:01

求大神解决!!!

import time
from selenium import webdriver
def login(login_qq,password,business_qq):
    '''

    :param login_qq: 登入用的QQ
    :param password: 登入用的QQ密码
    :param business_qq: 业务qQ
    :return: driver
    '''
    driver = webdriver.Chrome()

    driver.get('https://user.qzone.qq.com/{}/311'.format(business_qq))
    driver.implicitly_wait(10)
    driver.find_element_by_id('login_div')
    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(login_qq)
    driver.find_element_by_id('p').clear()
    driver.find_element_by_id('p').send_keys(password)
    driver.find_element_by_id('login_button').click()
    driver.switch_to.default_content()

    driver.implicitly_wait(10)
    time.sleep(5)

    try:
      driver.find_element_by_id('QM_OwnerInfo_Icon')
      return driver
    except:
      print('不能访问'+ business_qq)
      return



from bs4 importBeautifulSoup
def get_shuoshuo(driver):

    page = 1
    while True:
      for j in range(1,5):
            driver.execute_script('window.scrollBy(0,5000)')
            time.sleep(2)

      driver.switch_to.frame('app_canvas_frame')
      bs = BeautifulSoup(driver.page_source.encode('GBK','ignore').decode('gbk'))
      pres = bs.find_all('pre',class_='content')

      for pre in pres:
            shuoshuo = pre.text
            tx = pre.parent.parent.find('a',class_='c_tx3 goDetail')['title']
            print(tx + ':' +shuoshuo)

      page = page+1
      maxPage = bs.find('a',title='末页').text

      if int(maxPage)<page:

            break

      driver.find_element_by_link_text(u'下一页').click()

      driver.switch_to.default_content()

      time.sleep(3)


我该如何运行这个代码???   我用了基本方法都不行

Chysial 发表于 2020-8-20 17:50:31

你下载chrome驱动了吗?
页: [1]
查看完整版本: 求大神解决!!!