[M]add proxy
This commit is contained in:
parent
0dc6d037e9
commit
ec416d418d
@ -2,11 +2,14 @@ import os
|
||||
import random
|
||||
import time
|
||||
|
||||
from requests.api import get
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
import logging
|
||||
from mastodon import Mastodon
|
||||
import traceback
|
||||
import re
|
||||
|
||||
logging.basicConfig(filename='/home/captain/dev/log/jandan.log', level=logging.INFO)
|
||||
logger = logging.getLogger('/home/captain/dev/log/jandan.log')
|
||||
@ -46,7 +49,10 @@ def save_id(id_list):
|
||||
session = requests.session()
|
||||
|
||||
|
||||
def toot():
|
||||
def get_proxy():
|
||||
return requests.get("http://118.24.52.95:5010/get/").json()
|
||||
|
||||
def toot(proxy=None):
|
||||
jandan_pic_url = 'https://jandan.net/pic'
|
||||
page_count = 2
|
||||
status_list = []
|
||||
@ -55,9 +61,10 @@ def toot():
|
||||
id_list = []
|
||||
|
||||
session.headers.update(ramdom_ua())
|
||||
session.proxies.update({"http": "http://{}".format(proxy)})
|
||||
|
||||
while page_count and jandan_pic_url:
|
||||
resp = session.get(jandan_pic_url)
|
||||
resp = session.get(jandan_pic_url, timeout=2)
|
||||
if resp.status_code != 200:
|
||||
time.sleep(10)
|
||||
continue
|
||||
@ -127,7 +134,8 @@ def toot():
|
||||
while True:
|
||||
try:
|
||||
logger.info('%s !!!! start', time.asctime())
|
||||
toot()
|
||||
proxy = get_proxy()
|
||||
toot(proxy=proxy['proxy'])
|
||||
time.sleep(20)
|
||||
except Exception as ex:
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user