-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path11.py
62 lines (56 loc) · 1.69 KB
/
11.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
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import random
import datetime
global page
page=[]
global page,inn,outt
random.seed(datetime.datetime.now())
def getin(hhhh,urlin):
inn=[]
p=re.compile(urlin)
for hin in hhhh.findAll('a',{'href':p}) :
if hin.attrs['href'] not in inn:
inn.append(hin.attrs['href'])
page.append(hin.attrs['href'])
# inn.append(hin)
# print('内链列表:')
# print(inn)
return inn
def getout(hhhh,urlout):
outt=[]
for hout in hhhh.findAll('a',{'href':re.compile('^(http|www)((?!'+urlout+').)*$')}):
# for hout in hhhh.findAll('a'):
if hout.attrs['href'] not in outt:
outt.append(hout.attrs['href'])
page.append(hout.attrs['href'])
# print('外链列表:')
# print(outt)
return outt
def qieduan(url):
# print(url.replace('https://','').replace('http://','').replace('www.','').split('/')[0])
return url.replace('https://','').replace('http://','').replace('www.','').split('/')[0]
def wailian(url):
try:
h=urlopen(url)
hhhh=BeautifulSoup(h)
url=qieduan(url)
goo=getout(hhhh,url)
getin(hhhh,url)
getout(hhhh,url)
# print(goo)
if len(goo)>0:
return goo[random.randint(0,len(goo)-1)]
else:
return getin[random.randint(0,len(getin(hhhh,url))-1)]
except Exception as e:
dk(page[random.randint(0,len(page)-1)])
def dk(url):
print(url)
nurl=wailian(url)
dk(nurl)
dk('http://www.baidu.com/')
t=input('qsr:')
if t==a:
exit