用硒进行IP欺骗/购买共享代理?

问题描述 投票:3回答:1

我正在用硒刮擦电子商务网站,因为页面是由Javascipt加载的。

这是工作流程-:1.在发送随机用户代理的同时,以虚拟显示模式实例化Web diver驱动程序。使用随机用户代理会减少您被检测到的机会。这不会减少被IP阻塞的机会。2.对于每个查询词,说“睡衣”-为该网站创建搜索网址-并打开该网址。3.从Xpath获取相应的文本元素,例如前10个产品ID,价格,产品标题等。4.将它们存储在文件中-我将进一步处理

我有38000个以上的URL,我需要为页面加载中的元素获取这些URL。我进行了多处理,但我很快意识到该过程失败了,因为过了一会儿,网站被封锁了,所以页面加载没有发生。

我如何用Python进行IP欺骗,它将与为您而不是urllib / urlopen的硒驱动网络一起工作?

除了通过xpath设置实际的获取,这是基本代码-更具体地说,请参见init_driver

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import argparse
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import codecs, urllib, os
import multiprocessing as mp
from my_custom_path import scraping_conf_updated as sf
from fake_useragent import UserAgent

def set_cookies(COOKIES, exp, driver):
    for key, val in COOKIES[exp].items():
        driver.add_cookie({'name': key, 'value': val, 'path': '/', 'secure': False, 'expiry': None})
    return driver


def check_cookies(driver, exp):
    print "printing cookie name & value"
    for cookie in driver.get_cookies():
        if cookie['name'] in COOKIES[exp].keys():
            print cookie['name'], "-->", cookie['value']


def wait_for(driver):
    if conf_key['WAIT_FOR_ID'] != '':
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, conf_key['WAIT_FOR_ID'])))
    elif conf_key['WAIT_FOR_CLASS'] != '':
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.CLASS, conf_key['WAIT_FOR_CLASS'])))
    return driver



def init_driver(base_url, url, exp):
    display = Display(visible=0, size=(1024, 768))
    display.start()
    profile = webdriver.FirefoxProfile()
    ua = UserAgent(cache=False)
    profile.set_preference("general.useragent.override",ua.random)
    driver=webdriver.Firefox(profile)
    if len(conf_key['COOKIES'][exp]) != 0:
        driver.get(base_url)
        driver.delete_all_cookies()
        driver = set_cookies(COOKIES, exp, driver)
        check_cookies(driver, exp)
    driver.get(url)
    driver.set_page_load_timeout(300)
    if len(conf_key['POP_UP']['XPATH']) > 0:
        driver = identify_and_close_popup(driver)
    driver = wait_for(driver)
    return driver
python selenium ip multiprocessing spoofing
1个回答
0
投票

使用VPN提供商或http或短袜代理来更改您目标网站上的明显的始发IP地址

© www.soinside.com 2019 - 2024. All rights reserved.