1 Star 0 Fork 0

passionboyxie / toutiao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
toutiaologin.py 3.34 KB
一键复制 编辑 原始数据 按行查看 历史
passionboyxie 提交于 2020-10-26 17:58 . first commit
import requests
import json
import jsonpath
from selenium.webdriver.common.keys import Keys
header = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
url = 'https://36kr.com/api/newsflash?&per_page=20'
response = requests.get(url,
headers=header,
timeout=5
)
dict = json.loads(response.text)
title=jsonpath.jsonpath(dict,"$..title]")
des=jsonpath.jsonpath(dict, '$..description')
publish=jsonpath.jsonpath(dict, '$..published_at')
for i in range(20):
print(title[i]," ",des[i], " ", publish[i])
from selenium import webdriver
wait_time=2
Max_Time_Out=10
import os
import pickle
import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
option.binary_location = "/Applications/AppleTools /Google Chrome.app/Contents/MacOS/Google Chrome"
# option.add_argument('--headles')
brower = webdriver.Chrome()
wait = WebDriverWait(brower, 3)
def getTaobaoCookies():
# get login cookies
url = "https://mp.toutiao.com/profile_v3/index"
brower.get("https://mp.toutiao.com/auth/page/login/")
time.sleep(2)
username = brower.find_element_by_name("username")
username.clear()
username.send_keys("189")
brower.find_element_by_id("sso_code").click()
while True:
print("Please login in toutiao.com!")
time.sleep(3)
# if login in successfully, url jump to testerhome.com
if brower.current_url == url:
tbCookies = brower.get_cookies()
cookies = {}
for item in tbCookies:
cookies[item['name']] = item['value']
outputPath = open('Cookies.pickle', 'wb')
pickle.dump(cookies, outputPath)
outputPath.close()
# brower.close()
return cookies
print(getTaobaoCookies())
def readTaobaoCookies():
# if hava cookies file ,use it
# if not , getTaobaoCookies()
if os.path.exists('Cookies.pickle'):
readPath = open('Cookies.pickle','rb')
tbCookies = pickle.load(readPath)
else:
tbCookies = getTaobaoCookies()
return tbCookies
tbCookies = readTaobaoCookies()
print(tbCookies)
for cookie in tbCookies:
brower.add_cookie({
"domain":".tuotiao.com",
"name":cookie,
"value":tbCookies[cookie],
"path":'/',
"expires": None
})
brower.get("https://mp.toutiao.com/profile_v3/graphic/publish")
brower.refresh()
def type_toutiao(driver, title, description):
url = "https://mp.toutiao.com/profile_v3/graphic/publish"
driver.get(url)
driver.refresh()
time.sleep(5)
title_input = driver.find_element_by_tag_name("textarea")
title_input.clear()
title_input.send_keys(title)
title_input = driver.find_element_by_class_name("ProseMirror")
title_input.clear()
title_input.send_keys(description)
result=driver.find_elements_by_tag_name("input")
result[2].send_keys(Keys.SPACE)
time.sleep(1)
driver.find_element_by_id("publish").click()
time.sleep(3)
for i in range(20):
type_toutiao(brower,title[i],des[i])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/passionboyxie/toutiao.git
git@gitee.com:passionboyxie/toutiao.git
passionboyxie
toutiao
toutiao
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891