model / app.py
djl234's picture
Update app.py
6512c0f
'''import gradio as gr
import urllib.request
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'}
def getHtml(url):
print(url)
html = urllib.request.urlopen(url,headers).read()
return html
def saveHtml(file_name, file_content):
with open(file_name.replace('/', '_') + ".html", "wb") as f:
f.write(file_content)
usr_name_list=['NikaLegran']
with open('user.txt','rb') as f1:
usr_name_list=bytes.decode(f1.read()).split(' ')
#print(usr_name_list[:10])
for i in range(len(usr_name_list)):
#url = "http://www.view.sdu.edu.cn/info/1003/75240.htm"
usr_name=usr_name_list[i]
url = 'https://zh.stripchat.com/'+usr_name+'/profile'
html = getHtml(url)
saveHtml(''+usr_name, html)
if i%20==0:
print(i)
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()'''
import os
os.system("pip3 install selenium")
from selenium import webdriver
import time
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
edge_options = EdgeOptions()
edge_options.use_chromium = True
# 设置无界面模式,也可以添加其它设置
edge_options.add_argument('headless')
driver=Edge(options=edge_options)
usr_name_list=['NikaLegran']
with open('user.txt','rb') as f1:
usr_name_list=bytes.decode(f1.read()).split(' ')
print(usr_name_list[:10])
earned_list=[]
def get_profile(usr_name,rt='F:/model_profile/'):
get_html = rt+usr_name+".html"
#打开文件,准备写入
f = open(get_html,'wb')
url = 'https://zh.stripchat.com/'+usr_name+'/profile' # 这里填你要保存的网页的网址
driver.get(url)
time.sleep(0.9) # 保证浏览器响应成功后再进行下一步操作
#写入文件
f.write(driver.page_source.encode("utf-8", "ignore"))
f.close()
def cal_earned(usr_name,rt='F:/model_profile/'):
#get_profile(usr_name,'./')
f=open(rt+usr_name+'.html','rb')
data=bytes.decode(f.read())
Len_pre=len('"achieved-epic-goals__tokens">')
tot=0
ok=False
for i in range(len(data)-20):
if data[i:i+Len_pre]=='"achieved-epic-goals__tokens">':
ok=True
ptr=i+Len_pre
s=''
while data[ptr]!='代':
if data[ptr]!=',':
s+=data[ptr]
ptr+=1
tot+=(int(s))
f.close()
#earned_list.append(tot)
out_f.write(str(tot).encode())
out_f.write(' '.encode())
out_f=open('earned_result.txt','wb')
for i in range(0,len(usr_name_list)):
get_profile(usr_name_list[i])
#cal_earned(usr_name_list[i])
if i%10==0:
print(i)
if i%20==0:
driver.quit()
driver=Edge(options=edge_options)
out_f.close()