从手机抓取/抓取数据

时间:2020-08-17 07:58:10

标签: python python-3.x web-scraping

我有一个Python脚本(使用硒),可以通过在Google中搜索特定产品并获取所有必要信息来从Google抓取数据。

由于Google和Mobile的搜索结果完全不同,因此现在需要从Mobile获取这些数据。因此,我们希望从Mobile抓取数据。

我该怎么做?

在当前设置中,我已经在Jenkins中安排了该Python脚本,以自动抓取和抓取Google的数据。

但是要从Mobile获取数据,我该如何处理?您的建议会很有帮助吗?

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.common.exceptions import TimeoutException

for row in serach_url_list:
         sleep(30)
         mobile_emulation = { "deviceName": "Nexus 5" }
         options = webdriver.ChromeOptions()
         options.add_experimental_option("mobileEmulation", mobile_emulation)
         options.add_experimental_option("excludeSwitches", ["enable-automation"])
         options.add_experimental_option('useAutomationExtension', False)
         options.add_argument('--headless')
         browser = webdriver.Chrome(executable_path='/users/chromedrive/chromedriver', chrome_options=options)
         browser.implicitly_wait(30)
         
          passed_url=''
          passed_url=str(row)
          get_products(passed_url)


def get_products(url):
    product=[]
    print('Passed URL : '+url)
    browser.get(url)
    names = browser.find_elements_by_xpath("//span[@class='pymv4e']")
    product.clear()
    upd_product_name_list=list(filter(None, names))
    product_name = [x.text for x in upd_product_name_list]

1 个答案:

答案 0 :(得分:1)

您好,您可以在ChromeDriver中使用硒的移动仿真功能。以下资源具有Python代码示例: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation