抓取时获取空src

时间:2018-06-28 11:46:07

标签: android html web-scraping scrapy jsoup

我正在尝试使用Jsoup刮擦A网站的内容。由Jsoup解析的HTML的src属性为空(即src =“”),而当我在chrome中检查网站时,它显示的是非空的src(未用javascript填充)。这不仅仅是Jsoup的问题,Scrapy返回相同的结果(空src)。 我尝试添加自定义用户代理。

任何人都可以说出此问题的原因和可能的解决方案。 *我不能使用硒之类的方法,因为我正在寻找Android应用程序开发的解决方案。 谢谢!

编辑:

正在使用的站点是flipkart.com,我正在从其搜索结果https://www.flipkart.com/search?q=xbox&marketplace=FLIPKART&sid=search.flipkart.com中抓取

来自其“ img”标签的src被解析为空。

2 个答案:

答案 0 :(得分:1)

src属性为空。在浏览器中查看页面源并搜索该类。然后,您将发现src属性值为空。 enter image description here

答案 1 :(得分:-1)

您可以使用Selenium with Python来刮除此src属性。

#!/bin/bash/env python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get("https://www.flipkart.com/search?q=xbox&marketplace=FLIPKART&sid=search.flipkart.com")

elem = driver.find_elements(By.XPATH, '//img[@class="_1Nyybr"]')

for element in elem:
    print element.get_attribute('src')
    print element.get_attribute('class')

driver.close()

编辑

使用contains来获取结果。

elem = driver.find_elements_by_xpath('//img[contains(@class, "_30XEf0")]')