文章
问答
冒泡
selenium模拟浏览器配置代理
from selenium import webdriver
#find_element by可选的值
class By(object):
    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"
# 模拟浏览器配置
USERAGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
PROXY = 'http://127.0.0.1:8090'
url = 'https://www.xxxx.com'
option = webdriver.ChromeOptions()
option.add_argument('--headless')
option.add_argument('--disable-gpu')
option.add_argument('user-agent=' + USERAGENT)
option.add_argument("--proxy-server=" + PROXY)
driver = webdriver.Chrome(chrome_options=option)
driver.set_page_load_timeout(20)
driver.get(url)
# 模拟点击和输入操作
def get_element(**kwargs):
    """
    kwargs = {by: 'tag name', value: span}
    """
    by = kwargs.get('by', 'css selector')
    value = kwargs.get('value', '')
    return driver.find_element(by=by, value=value)

def mock_click(element):
    element.click()

def mock_input(element, input_value, is_submit=False):
    element.send_keys(input_value)
    is_submit and element.submit()
爬虫

关于作者

zhyim
学海无涯,回头是岸
获得点赞
文章被阅读