-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrawler.py
103 lines (83 loc) · 2.64 KB
/
scrawler.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/local/bin/python3.5
# -*- coding: UTF-8 -*-
from requests import session
from bs4 import BeautifulSoup
import os
file_drama_history = "drama_history.txt"
file_drama_list = "new_drama_list.txt"
# Clear the file contents
f = open(file_drama_list, "w")
f.close()
s = session()
r = s.get("http://kanmeiju.net/detail/2272.html")
bs = BeautifulSoup(r.text, "lxml")
urls = bs.select("body > div.wrap > div > div > div > ul > a")
for url in urls:
url_text = url.get('href')
# Find if the drama has already been watched
count = 0
with open(file_drama_history, "r") as f:
for old_url in f.readlines():
li = old_url.find(url_text)
if li != -1:
count += 1
break
f.close()
if count == 0:
with open(file_drama_history, "a") as f:
f.write(url_text)
f.write("\n")
f.close()
with open(file_drama_list, "a") as f_dl:
f_dl.write(url_text)
f_dl.write("\n")
f_dl.close()
r = s.get("http://kanmeiju.net/detail/2291.html")
bs = BeautifulSoup(r.text, "lxml")
urls = bs.select("body > div.wrap > div > div > div > ul > a")
for url in urls:
url_text = url.get('href')
# Find if the drama has already been watched
count = 0
with open(file_drama_history, "r") as f:
for old_url in f.readlines():
li = old_url.find(url_text)
if li != -1:
count += 1
break
f.close()
if count == 0:
with open(file_drama_history, "a") as f:
f.write(url_text)
f.write("\n")
f.close()
with open(file_drama_list, "a") as f_dl:
f_dl.write(url_text)
f_dl.write("\n")
f_dl.close()
r = s.get("http://kanmeiju.net/detail/2304.html")
bs = BeautifulSoup(r.text, "lxml")
urls = bs.select("body > div.wrap > div > div > div > ul > a")
for url in urls:
url_text = url.get('href')
# Find if the drama has already been watched
count = 0
with open(file_drama_history, "r") as f:
for old_url in f.readlines():
li = old_url.find(url_text)
if li != -1:
count += 1
break
f.close()
if count == 0:
with open(file_drama_history, "a") as f:
f.write(url_text)
f.write("\n")
f.close()
with open(file_drama_list, "a") as f_dl:
f_dl.write(url_text)
print(url_text + "\n")
f_dl.write("\n")
f_dl.close()
s.close()
#os.system("/Applications/TextEdit.app/Contents/MacOS/TextEdit /Users/Jia/Work/Python/Drama_scrawler/new_drama_list.txt")