-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifeng.py
More file actions
36 lines (25 loc) · 668 Bytes
/
ifeng.py
File metadata and controls
36 lines (25 loc) · 668 Bytes
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
33
34
import urllib
from bs4 import BeautifulSoup
url = "http://www.ifeng.com"
html = ""
def getHTML():
response = urllib.urlopen(url)
global html
html = response.read()
print html
def parse():
soup = BeautifulSoup(html, "html.parser")
importDiv = soup.select("div[id=headLineDefault]")
head = importDiv[0]
ulList = head.select("ul[class=FNewMTopLis]")
newsList = ulList[0]
liList = newsList.select("li")
for index in range(len(liList)):
item = liList[index]
aList = item.select("a")
if len(aList) == 1:
print item.string
while(True):
getHTML()
parse()
# time.sleep(600)