-
Notifications
You must be signed in to change notification settings - Fork 0
/
newLists.py
32 lines (29 loc) · 1.07 KB
/
newLists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from bs4 import BeautifulSoup
import requests
import os,re,time
from selenium import webdriver
# PhantomJS
class GetNewsLists():
def __init__(self):
self.driver = webdriver.Chrome()
def start(self,url):
self.driver.get(url)
time.sleep(5)
soup = BeautifulSoup(self.driver.page_source, 'lxml')
#获取新闻日期
select = "#monthly .weeklist .heightLineParent a"
y1 = soup.select(select)
newDate = [x['id'] for x in y1]
dict = {}
#点击选择新闻日期
# select_date = '#'+newDate[2]
self.driver.find_element_by_css_selector("#monthly > div > ul > li:nth-child(2)").click()
time.sleep(5)
#获取新闻列表
soup2 = BeautifulSoup(self.driver.page_source, 'lxml')
select2 = "ul.newslisteven a"
y2 = soup2.select(select2)
dict[newDate[2]] = ['http://www3.nhk.or.jp/news/easy' + x['href'][1:] for x in y2]
return dict
print(GetNewsLists().start('http://www3.nhk.or.jp/news/easy/index.html'))
#monthly > div > ul > li:nth-child(2)