methods width and height Mechanize

两盒软妹~` 提交于 2019-12-25 08:19:10

问题


I'm using Mechanize for scraping images url then I'm looking http://mechanize.rubyforge.org/Mechanize/Page/Image.html for to know width and height images.

I write in console:

url = "http://www.bbc.co.uk/"
page = Mechanize.new.get(url)
images_url = page.images.map{|img| img.width}.compact

I get the result:

["1", "84", "432", "432", "432", "432", "432", "432", "432", "304", "144", "144", "144", "144", "144", "144", "432", "432", "432", "432", "432", "432", "432", "336", "62", "62", "62", "62", "84", "1", "0"]

This result works fine for me I get image's width.

However with others web pages I get nil e.g. you can check with this web page:

url = "http://www.glamourum.com" #check also with https://www.birchbox.com/
page = Mechanize.new.get(url)
images_url = page.images.map{|img| img.width}.compact

I get a result:

=> []

an array empty :O or for https://www.birchbox.com/ I get an array with:

=> ["1", "1", "1", "1", "1"]

why this happens with some websites and does not occur with other websites?

What is the solution for this problem?


回答1:


Mechanize doesn't fetch the images. It can only return you the size as reflected on the img tag in the HTML and a lot sites don't include that.



来源:https://stackoverflow.com/questions/9447571/methods-width-and-height-mechanize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!