Android Question download image from google image search

mohsen nasrabady

Active Member
Licensed User
B4X:
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?
 

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
 

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

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

Attachments

  • 69.4 KB Views: 69

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
 

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.
 

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:

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
 

mohsen nasrabady

Active Member
Licensed User
B4X:
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?
this code does not work now because google changed the code page (worked good until about month ago) can anyone help?
 
Last edited:

somed3v3loper

Well-Known 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
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 .
 
Top