Android Question download image from google image search

Discussion in 'Android Questions' started by mohsen nasrabady, Mar 23, 2015.

  1. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    how can download images from google image search with httputils2?
     
  2. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    Code:
    Sub JobDone (Job As HttpJob)
        
    Dim TextReader1 As TextReader
        TextReader1.Initialize(Job.GetInputStream)
        
    Dim pattern, class As String
        class = 
    "href"
        pattern = 
    "src=\q([^q]+)\q".Replace("q"QUOTE)
       
        
    Dim line As String
        line = TextReader1.ReadLine
        
    Do While line <> Null
            
    If line.IndexOf(class) > -1 Then
                
    Dim m As Matcher
                m = 
    Regex.Matcher(pattern, line)
                
    Do While m.Find <> False
                    
    Dim ImageJob As HttpJob
                    ImageJob.Initialize(
    "ImageJob", Me)
                    ImageJob.Download(m.Group(
    1))
                
    Loop
            
    End If
            line = TextReader1.ReadLine
        
    Loop
        TextReader1.Close
    End Sub
    i used this code but the link downloaded is in very low size
    and smaller than google image size
    how can fix that?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    HttpUtils2 downloads the resource as is. You will need to find the correct link to the full size image.
     
    Peter Simpson likes this.
  4. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    i dont want the orginal size image but in pc search the images is about 11kb but with this code images is about 3kb and very smaller
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Again, you will need to find the correct link. It is also possible that google returns different links based on the user agent header.
     
    Peter Simpson likes this.
  6. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    i run this code with b4j in pc and the return image is also in small size it is not related about phone or pc

    this file is a example page if u can pls help me i can't understand web page codes, ty

    and this is the link of this page file

    Code:
    J.Download("https://www.google.com/search?q=car_2%20psp%20screenshot&ie=UTF-8&hl=en&tbm=isch")
     

    Attached Files:

    • 1.txt
      File size:
      69.4 KB
      Views:
      56
  7. Troberg

    Troberg Well-Known Member Licensed User

    It's not about the OS, it's about the browser.
     
  8. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    ty u for ur help i changed the link to a link that chroome return in my pc and the size of image is also very small
    but in the browser is bigger

    and also some of link do not return an image
     
  9. Troberg

    Troberg Well-Known Member Licensed User

    In a http request, there is a field that tells the server which browser (user agent) the request comes from. It is possible for the server to use that to determine what to send. If you can change that field, you can bypass it, if not, there is not much you can do about it.
     
  10. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    in the above i uploaded the web page file i can't understand web page code pls help me if u can
    lookat the file pls and help me how can chande user agent with httputils2
    is it possible with method post sting? or with download2 ?
     
    Last edited: Mar 24, 2015
  11. DonManfred

    DonManfred Expert Licensed User

    Search the forum on how to set a useragent with httputils! You will find the answer. Erel already stated this to you (using a useragent)
    There is no need that anyone other does this for you
     
    Troberg likes this.
  12. Troberg

    Troberg Well-Known Member Licensed User

    DonManfred likes this.
  13. DonManfred

    DonManfred Expert Licensed User

    Troberg likes this.
  14. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    tnx alot all very useful now the size of images is like pc and good quality
    but the links returned is not in order to search google

    with out the user agent the image is small but in order
    this is not very bad problem thnx all
     
  15. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    this code does not work now because google changed the code page (worked good until about month ago) can anyone help?
     
    Last edited: Sep 13, 2016
  16. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

  17. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    J.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0")

    with this user agent cant get links
     
  18. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

    I tested UA you provided and it returned fewer results than before .
    I changed it to "OPR/15.0.1147.100" and it seems to work again .
     
  19. mohsen nasrabady

    mohsen nasrabady Active Member Licensed User

    but in my samsung s6 edge plus no link return
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice