【发布时间】:2018-05-31 20:24:16
【问题描述】:
我要废弃的网站是:
http://www.mouthshut.com/mobile-operators/Reliance-Jio-reviews-925812061
我想获取上面链接的最后页码进行操作,截屏时是499。
我的代码:
from bs4 import BeautifulSoup
from urllib.request import urlopen as uReq
from selenium import webdriver;import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/etc/firefox'
driver = webdriver.Firefox(capabilities=firefox_capabilities)
url = "http://www.mouthshut.com/mobile-operators/Reliance-Jio-reviews-925812061"
driver.get(url)
wait = WebDriverWait(driver, 10)
soup=BeautifulSoup(driver.page_source,"lxml")
containers = soup.findAll("ul",{"class":"pages table"})
containers[0] = soup.findAll("li")
li_len = len(containers[0])
for item in soup.find("ul",{"class":"pages table"}) :
li_text = item.select("li")[li_len].text
print("li_text : {}\n".format(li_text))
driver.quit()
我需要帮助来找出获取最后页码的代码中的错误。另外,如果有人提供相同的替代解决方案并提出实现我的意图的方法,我将不胜感激。
【问题讨论】:
-
如果我在小屏幕上运行页面,那么它不会显示带有 499 的按钮 - 这没有地方。如果我在移动设备上运行它不会显示分页但按钮“显示更多”
-
顺便说一句:您总是可以获得评论数量
9976并计算math.ceil(9976/20) -
作为python的初学者,您的建议对我非常有用。我会期待的。谢谢!
标签: python selenium selenium-webdriver beautifulsoup screen-scraping