#!/usr/bin/env python
# -*- coding:utf-8 -*-
from selenium import webdriver
from bs4 import BeautifulSoup as bs
from 通用列表爬虫.util.rqst import get_html
from 通用列表爬虫.util.common import printred, saveTxt, rewriteTxt, getRewriteTxt
class douyu():
# driver = webdriver.Chrome(executable_path=rD:Program Fileschromedriver.exe)
driver = webdriver.PhantomJS(executable_path=rD:Program Filesphantomjs-2.1.1-windowsinphantomjs.exe)
num = 0
count = 0
# 测试方法必须有test字样开头
def testDouyu(self):
self.driver.get("http://catalogue.hyve.ru/ru-RU/exhibitorlist.aspx?project_id=456")
while True:
self.count = self.count +1
if(self.count>9): # 第九页
printred("DONE")
return
printred("=================开始 "+str(self.count)+"===============")
soup = bs(self.driver.page_source, "lxml")
ids = soup.find_all("a", {"class" : "popUp"})
for i in ids:
a= i.find("div", {"class" : "name"}).text.replace(
,)
b= i.find("div", {"class" : "country"}).text.replace(
,)
c= i.find("div", {"class" : "pavilion"}).text.replace(
,)
d= i.find("div", {"class" : "stand"}).text.replace(
,)
h = http://catalogue.hyve.ru+i[href]
html = bs(get_html(h), "lxml")
ctt = html.find("div", {"class" : "scorecard"})
j = ctt.h2.text
k = ctt.p.text.replace(
,)
l = ctt.find_all("p")[2].text.replace(
,)
m = ctt.find_all("p")[3].text.replace(
,)
n = ctt.find_all("p")[4].text.replace(
,)
o = ctt.find_all("p")[5].text.replace(
,)
p = ctt.find_all("p")[7].text.replace(
,)
q = ctt.find_all("p")[8].text.replace(
,)
r = ctt.find_all("p")[9].text
print(
a+
+b+
+c+
+d+
+h+
+j+
+k+
+l+
+m+
+n+
+o+
+p+
+q+
+r+
)
saveTxt(1.txt, a+
+b+
+c+
+d+
+h+
+j+
+k+
+l+
+m+
+n+
+o+
+p+
+q+
+r+ )
print("==============================")
self.driver.find_element_by_css_selector(r#form > section > div > div.pager > a:nth-child(12)).click()
# # 房间号, 返回列表
# ids = soup.find_all("a", {"class" : "play-list-link"})
# # 房间名, 返回列表
# names = soup.find_all("h3", {"class" : "ellipsis"})
def tearDown(self):
# 退出Firefox()浏览器
# print ("当前网站直播人数" + str(self.num))
# print ("当前网站观众人数" + str(self.count))
self.driver.quit()
if __name__ == "__main__":
# 启动测试模块
d = douyu()
d.testDouyu()
d.tearDown()