首页 > 其他 > 详细

第五天

时间:2019-06-17 23:46:18      阅读:112      评论:0      收藏:0      [点我收藏+]
import requests
import re


import time

‘‘‘
    url:
        https://www.kuaidaili.com/free/
    Request URL:
        https://www.kuaidaili.com/free/inha/1/
    Request Method: 
        GET
    请求头:
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
‘‘‘

headers = {
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
}

def get_index(url):
    
    response = requests.get(url, headers=headers)
    # print(response.text)
    return response

def parse_text(text):
    ‘‘‘
    正则匹配ip和端口
    <tr>
                    <td data-title="IP">117.91.248.174</td>
                    <td data-title="PORT">9999</td>
                    <td data-title="匿名度">高匿名</td>
                    <td data-title="类型">HTTP</td>
                    <td data-title="位置">江苏省扬州市  电信</td>
                    <td data-title="响应速度">2秒</td>
                    <td data-title="最后验证时间">2019-06-17 19:30:59</td>
                </tr>
<td data-title="IP">(.*?)</td>.*?<td data-title="PORT">(.*?)</td>

‘‘‘
    ip_list = re.findall(<td data-title="IP">(.*?)</td>.*?<td data-title="PORT">(.*?)</td>, text, re.S)
    for ip_port in ip_list:
        ip = :.join(ip_port)
        return ip
        # print(ip)

def ip_test(ip):
    # print(‘测试的ip: %s‘ % ip)
    try:
        proxies = {
            http: ip
        }
        ip_test_url = https://www.ipip.net/

        response = requests.get(ip_test_url, headers=headers, proxies=proxies)

        if response.status_code == 200:
            # print(response.text)
            return ip
    except Exception as e:
        print(e)



if __name__ == __main__:
    initial_url = https://www.kuaidaili.com/free/inha/{}/
    for line in range(1, 2905):
        ip_url = initial_url.format(line)

        response = get_index(ip_url)

        ip_list = parse_text(response.text)

        ip = ip_test(ip_list)

        if ip:
            with open(ip.txt, a) as f:
                f.write(ip+"\n")
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time

chrome = webdriver.Chrome()

try:
    wait = WebDriverWait(chrome, 10)
    chrome.get(https://dig.chouti.com/)
    time.sleep(1)
    login_button = wait.until(EC.presence_of_element_located((By.ID, "login_btn")))
    login_button.click()
    time.sleep(1)
    input_phone = wait.until(
        EC.presence_of_element_located((By.NAME, "phone"))
    )
    input_phone.send_keys(17681330406)
    time.sleep(2)
    input_pwd = wait.until(
            EC.presence_of_element_located((By.NAME, "password"))
    )
    input_pwd.send_keys(19970406ZZZ)
    time.sleep(1)
    input_pwd.send_keys(Keys.ENTER)

finally:
    time.sleep(10)
    chrome.close()

 

第五天

原文:https://www.cnblogs.com/Vvvvyy/p/11042641.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!