我正在尝试从使用angularjs(https://paytm.com/shop/p/masha-brown-cotton-night-wear-APPMASHA-BROWN-BBOY22296974F0BD7?src=grid&tracker=%7C%7C%7C%7C%2Fg%2Fwomen%2Flingerie-sleepwear%2Fnight-dresses-nighties%7C5845%7C8)的市场中搜集产品数据。
我可以使用selenium python获取大部分细节: -
import platform
from bs4 import BeautifulSoup
from selenium import webdriver
import time
# Phantomjs path
if platform.system() == 'Windows':
PHANTOMJS_PATH = './phantomjs.exe'
else:
PHANTOMJS_PATH = './phantomjs'
browser = webdriver.PhantomJS(PHANTOMJS_PATH)
browser.get('https://paytm.com/shop/p/masha-brown-cotton-night-wear-APPMASHA-BROWN-BBOY22296974F0BD7?src=grid&tracker=%7C%7C%7C%7C%2Fg%2Fwomen%2Flingerie-sleepwear%2Fnight-dresses-nighties%7C5845%7C8')
time.sleep(3)
element = browser.find_element_by_css_selector("h1[class='dotted-border']");
title = element.text
print title
element1 = browser.find_element_by_css_selector("span[ng-if='!product.product.isOnlyCarCategory']");
price = element1.text
price = int(price.replace('Buy for Rs ',''))
print price
element2 = browser.find_element_by_css_selector("a[ng-click='product.sendSellerTracking(product.product.merchant.merchant_name)']");
seller_name = element2.text
print seller_name
element3 = browser.find_element_by_xpath("//li[@class='shown-image active']/img");
img_url = element3.get_attribute('src')
print img_url
element4 = browser.find_element_by_css_selector("span[class='rating-text']");
vendor_rating = element4.text
print vendor_rating
使用selenium python。我是新手,因此无法弄清楚我们如何抓取UI元素,然后在另一个网页上显示它。我搜索了很多但却无法找到适合我查询的内容。如果有人可以帮助我,那就太好了。
由于