Skip to content

Commit

Permalink
Signed-off-by: alivon <[email protected]>
Browse files Browse the repository at this point in the history
  • Loading branch information
alivon committed Apr 12, 2019
1 parent e862e79 commit 0e6e849
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 69 deletions.
49 changes: 30 additions & 19 deletions Source Packages/pdlearn/get_links.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import requests
import re


def get_article_links():
article = requests.get(
"https://www.xuexi.cn/c06bf4acc7eef6ef0a560328938b5771/data9a3668c13f6e303932b5e0e100fc248b.js").content.decode(
"utf8")
pattern = r"list\"\:(.+),\"count\"\:"
links = []
list = eval(re.search(pattern, article).group(1))[:20000]
list.reverse()
for i in range(len(list)):
links.append(list[i]["static_page_url"])
return links
try:
article = requests.get(
"https://www.xuexi.cn/c06bf4acc7eef6ef0a560328938b5771/data9a3668c13f6e303932b5e0e100fc248b.js").content.decode(
"utf8")
pattern = r"list\"\:(.+),\"count\"\:"
links = []
list = eval(re.search(pattern, article).group(1))[:20000]
list.reverse()
for i in range(len(list)):
links.append(list[i]["static_page_url"])
return links
except:
print("=" * 120)
print("get_article_links获取失败")
print("=" * 120)
raise


def get_video_links():
video = requests.get(
"https://www.xuexi.cn/4426aa87b0b64ac671c96379a3a8bd26/datadb086044562a57b441c24f2af1c8e101.js").content.decode(
"utf8")
pattern = r'https://www.xuexi.cn/[^,"]*html'
link = re.findall(pattern, video, re.I)
link.reverse()
return link


try:
video = requests.get(
"https://www.xuexi.cn/4426aa87b0b64ac671c96379a3a8bd26/datadb086044562a57b441c24f2af1c8e101.js").content.decode(
"utf8")
pattern = r'https://www.xuexi.cn/[^,"]*html'
link = re.findall(pattern, video, re.I)
link.reverse()
return link
except:
print("=" * 120)
print("get_video_links获取失败")
print("=" * 120)
raise
74 changes: 40 additions & 34 deletions Source Packages/pdlearn/mydriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,47 @@
class Mydriver:

def __init__(self, noimg=True, nohead=True):
self.options = Options()
if os.path.exists("./chrome/chrome.exe"): # win
self.options.binary_location = "./chrome/chrome.exe"
elif os.path.exists("/opt/google/chrome/chrome"): # linux
self.options.binary_location = "/opt/google/chrome/chrome"
if noimg:
self.options.add_argument('blink-settings=imagesEnabled=false') # 不加载图片, 提升速度
if nohead:
self.options.add_argument('--headless')
self.options.add_argument('--disable-extensions')
self.options.add_argument('--disable-gpu')
self.options.add_argument('--no-sandbox')
self.options.add_argument('--mute-audio') # 关闭声音
self.options.add_argument('--window-size=400,500')
self.options.add_argument('--window-position=800,0')
self.options.add_argument('--log-level=3')
try:
self.options = Options()
if os.path.exists("./chrome/chrome.exe"): # win
self.options.binary_location = "./chrome/chrome.exe"
elif os.path.exists("/opt/google/chrome/chrome"): # linux
self.options.binary_location = "/opt/google/chrome/chrome"
if noimg:
self.options.add_argument('blink-settings=imagesEnabled=false') # 不加载图片, 提升速度
if nohead:
self.options.add_argument('--headless')
self.options.add_argument('--disable-extensions')
self.options.add_argument('--disable-gpu')
self.options.add_argument('--no-sandbox')
self.options.add_argument('--mute-audio') # 关闭声音
self.options.add_argument('--window-size=400,500')
self.options.add_argument('--window-position=800,0')
self.options.add_argument('--log-level=3')

self.options.add_argument('--user-agent={}'.format(user_agent.getheaders()))
self.options.add_experimental_option('excludeSwitches', ['enable-automation']) # 绕过js检测
self.webdriver = webdriver
if os.path.exists("./chrome/chromedriver.exe"): # win
self.driver = self.webdriver.Chrome(executable_path="./chrome/chromedriver.exe",
chrome_options=self.options)
elif os.path.exists("./chromedriver"): # linux
self.driver = self.webdriver.Chrome(executable_path="./chromedriver",
chrome_options=self.options)
elif os.path.exists("/usr/lib64/chromium-browser/chromedriver"): # linux 包安装chromedriver
self.driver = self.webdriver.Chrome(executable_path="/usr/lib64/chromium-browser/chromedriver",
chrome_options=self.options)
elif os.path.exists("/usr/local/bin/chromedriver"): # linux 包安装chromedriver
self.driver = self.webdriver.Chrome(executable_path="/usr/local/bin/chromedriver",
chrome_options=self.options)
else:
self.driver = self.webdriver.Chrome(chrome_options=self.options)
except:
print("=" * 120)
print("Mydriver初始化失败")
print("=" * 120)
raise

self.options.add_argument('--user-agent={}'.format(user_agent.getheaders()))
self.options.add_experimental_option('excludeSwitches',
['enable-automation'])
self.webdriver = webdriver
if os.path.exists("./chrome/chromedriver.exe"): # win
self.driver = self.webdriver.Chrome(executable_path="./chrome/chromedriver.exe",
chrome_options=self.options)
elif os.path.exists("./chromedriver"): # linux
self.driver = self.webdriver.Chrome(executable_path="./chromedriver",
chrome_options=self.options)
elif os.path.exists("/usr/lib64/chromium-browser/chromedriver"): # linux 包安装chromedriver
self.driver = self.webdriver.Chrome(executable_path="/usr/lib64/chromium-browser/chromedriver",
chrome_options=self.options)
elif os.path.exists("/usr/local/bin/chromedriver"): # linux 包安装chromedriver
self.driver = self.webdriver.Chrome(executable_path="/usr/local/bin/chromedriver",
chrome_options=self.options)
else:
self.driver = self.webdriver.Chrome(chrome_options=self.options)

def login(self):
print("正在打开二维码登陆界面,请稍后")
Expand Down
25 changes: 16 additions & 9 deletions Source Packages/pdlearn/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@


def get_score(cookies):
jar = RequestsCookieJar()
for cookie in cookies:
jar.set(cookie['name'], cookie['value'])
total = requests.get("https://pc-api.xuexi.cn/open/api/score/get", cookies=jar).content.decode("utf8")
total = int(json.loads(total, encoding="utf8")["data"]["score"])
each = requests.get("https://pc-api.xuexi.cn/open/api/score/today/queryrate", cookies=jar).content.decode("utf8")
each = json.loads(each, encoding="utf8")["data"]["dayScoreDtos"]
each = [int(i["currentScore"]) for i in each if i["ruleId"] in [1, 2, 9, 1002, 1003]]
return total, each
try:
jar = RequestsCookieJar()
for cookie in cookies:
jar.set(cookie['name'], cookie['value'])
total = requests.get("https://pc-api.xuexi.cn/open/api/score/get", cookies=jar).content.decode("utf8")
total = int(json.loads(total, encoding="utf8")["data"]["score"])
each = requests.get("https://pc-api.xuexi.cn/open/api/score/today/queryrate", cookies=jar).content.decode(
"utf8")
each = json.loads(each, encoding="utf8")["data"]["dayScoreDtos"]
each = [int(i["currentScore"]) for i in each if i["ruleId"] in [1, 2, 9, 1002, 1003]]
return total, each
except:
print("=" * 120)
print("get_video_links获取失败")
print("=" * 120)
raise
2 changes: 1 addition & 1 deletion Source Packages/pdlearn/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def shutdown(stime):
print("\r{}秒后关机".format(stime-i), end="")
sleep(1)
else:
print("无自动关机任务,已程序释放内存,00分钟后窗口将自动关闭")
print("无自动关机任务,已释放程序内存,10分钟后窗口将自动关闭")
sleep(600)
12 changes: 6 additions & 6 deletions Source Packages/pdlearn/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def up_info():
print("\n正在联网获取更新信息...")
__Version = "v2.4"
__Version = "v2.5"
__INFO = "熊猫学习唯一下载地址为 https://github.com/Alivon/Panda-Learning"
try:
updata_log = requests.get(
Expand All @@ -15,12 +15,12 @@ def up_info():
print("="*120)
if __Version != updata_log[1].split("=")[1]:
print("当前不是最新版本,建议更新")
print("=" * 120)
print("更新提要:")
for i in updata_log[2:]:
print(i)
print("=" * 120)
print("更新提要:")
for i in updata_log[2:]:
print(i)
print("=" * 120)
print("更新显示不会打断之前输入操作,请继续...")
print("更新显示不会打断之前输入等操作,请继续......(若已输入用户标记直接enter)")
except:
print("版本信息网络错误")

Expand Down
Binary file added img_folder/防检测.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e6e849

Please sign in to comment.