from selenium import webdriver from selenium.webdriver.chrome.options import Options url_seed = ‘http://m.sogou.com/web/searchList.jsp?pid=sogou-mobb-123asd-0007&keyword=百度地图‘ mobile_emulation = { "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0}, "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"} chrome_options = Options() chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) browser = webdriver.Chrome(chrome_options=chrome_options) browser.get(url_seed) js = ‘document.getElementsByClassName("input-default js_input")[0].value="深圳市南山区海岸城"‘ browser.execute_script(js) xp = ‘//*[@id="sogou_vr_21384401_1_wrap"]/div/div[1]/a‘ browser.find_element_by_xpath(xp).click()
时间: 2024-10-25 09:44:44