-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegmentfault.py
34 lines (27 loc) · 875 Bytes
/
segmentfault.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
import json
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import post_reader
import segmentfault_login
import segmentfault_writer
base_url = 'https://segmentfault.com/'
driver = webdriver.Chrome()
driver.get(base_url)
driver.delete_all_cookies()
timeout = 5
try:
with open('segmentfault_cookies.json', 'r', encoding='utf-8') as f:
cookies = json.loads(f.read())
except FileNotFoundError:
cookies = json.loads(segmentfault_login.qq(driver, timeout))
for cookie in cookies:
driver.add_cookie({
'name': cookie['name'],
'value': cookie['value'],
'path': cookie['path'],
'domain': cookie['domain'],
'secure': cookie['secure']
})
driver.get('https://segmentfault.com/')
mypost = post_reader.read_file('your_post.md')
segmentfault_writer.write(mypost, driver, timeout)