how do I add captcha from a website to an app - android

I am trying t build an app that lets you search your train reservation details, the website has a Captcha to it, I need help with adding that captcha to the app.
Basically I'm trying to turn this page into an app: http://www.indianrail.gov.in/pnr_Enq.html

Try this:
As I can see what you want is this part
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id="captchaimg">
now you have the Id of the element, use Jsoup:
Document doc = Jsoup.connect("http://www.indianrail.gov.in/pnr_Enq.html").get();
Elements imgCaptcha= doc.select("#captchaimg");
String imgSrc=imgCaptcha.attr("src");
Log.d(Tag,"image source = "+imgSrc);
now create a stream and download it from imgSrc

Related

How do you scrape an image from a website using Flutter?

Hi I'm trying to do a simple task of getting the img src url from a website but I can't seem to do it, I've tried various flutter packages and now I've reverted back to vanilla Flutter. This is my code:
onPressed: () async {
http.Response response = await http.get('https://tiktok.com/#$enteredUsername');
dom.Document document = parser.parse(response.body);
final elements = document.getElementsByClassName('jsx-581822467');
print(elements);
},
I'm simply trying to get the image URL from this website (tiktok.com):
I've looked into the source code and it says the class name is 'jsx-581822467', but if I try to use that in the code it returns with a blank list.
How can I just simply get the URL of this profile picture? And the other elements with the 'jsx' prefix as their class names?
I think I figured out what your problem is. The inspector of the web browser displays the HTML on a TikTok profile page. However, this is only generated with JavaScript once the page is loaded. If we download the content via http.get(), we get the raw HTML before JavaScript can do any changes.
Write http.get(), in front of your URL or right-click on the website and click on View Page Source. Now the HTML will be displayed in the same way as your app gets it.
Search for avatar-wrapper round. You won't be able to find it, because the tag from the profile picture doesn't exist here yet.
Fortunately, the URL of the profile picture is already included in other places. Search for <meta property="og:image" content=". You will find only one hit and after the hit the URL of the profile picture starts directly.
Therefore, in my opinion, the easiest way to get the URL is:
download HTML.
remove all text up to <meta property="og:image" content=".
all following characters up to the next " are the URL we are looking for.
Here I have inserted my code, which worked fine for me:
Future<String> getProfileImageUrl(String username) async {
// Download the content of the site
http.Response response = await http.get("https://www.tiktok.com/#$username");
String html = response.body;
// The html contains the following string exactly one time.
// After this specific string the url of the profile picture starts.
String needle = '<meta property="og:image" content="';
int index = html.indexOf(needle);
// The result of indexOf() equals -1 if the needle didn't occurred in the html.
// In that case the received username may be invalid.
if (index == -1)
return null;
// Remove all characters up to the start of the text snippet that we want.
html = html.substring(html.indexOf(needle) + needle.length);
// return all chars until the first occurrence of '"'
return html.substring(0, html.indexOf('"'));
}
I hope that I could help you with my explanation.
Edit 1: General approach
view page source to view HTML of the page
search for the desired substring.
Select the previous 10 to 15 characters and see how often this string occurs before.
If it occurs more than once, you must call html = html.substring(html.indexOf(needle) + needle.length); accordingly often repeatedly.
reload the page and check if it still works.
now you have found your needle string.

All webview content printed in one page

Case: User should be able to view and print pdf
My solution: I am opening PDF inside Webview with the help of docs.google.com/gview. Below is my code
Set up Webview
string url = "http://www.africau.edu/images/default/sample.pdf";
string gview = $"https://docs.google.com/gview?embedded=true&url={url}";
mWebView.LoadUrl(gview);
Print PDF
var printMgr = (PrintManager)GetSystemService(PrintService);
printMgr.Print("print", mWebView.CreatePrintDocumentAdapter("print"), null);
Below is the screenshot. As you can see PDF loads just fine
Problem
When I want to print PDF, all the PDF pages are printed in one paper which you can see below
I would appreciate any suggestion, including different library for displaying/printing pdf or suggestion in Java or Kotlin, I can convert them to C#.
I would not print the web page but print the PDF directly as when printing the web page it just sees it as a longer web page and knows nothing about the content.
Use a custom print adapter instead, but instead of drawing a PDF to print you can just use the existing PDF you already have.
See for details https://developer.android.com/training/printing/custom-docs.html

How can I redirect my users to a specific label when they visit my blog?

I'm starting a new blog and I want to streamline things for mobile users. How can I detect mobile users and redirect them to an specific label on my blog?
I searched around in the settings of blogger and the only thing that caught my attention really was the option to edit the html. I really have no clue what to do there to be honest though if thats what I need to edit.
You can use Blogger code data:blog.isMobileRequest and javascript.
<b:if cond='data:view.isHomepage and data:blog.isMobileRequest'>
<script>
var $tag = "YOUR_TAG";
document.location = document.location.origin + "/search/label/" + $tag;
</script>
</b:if>
Edit HTML and put the code after <head> then save the template.
The code checks if the URL has parameter m=1 then it redirects to the chosen tag, and it only redirect home page url to prevent multiple redirects.

how to extract text from a html website in android

I want to develop an android application which takes a particular input from the app and gives it to a website, then the website fetches the result. I want to display this result from the website and display it in the android app. I tried using xml parsing but the website is not a xml based website. The website is http://www.fastvturesults.com/ and the input is a roll number(usn number). Can anyone guide me on how to fecth the result from this site and parse it to the app.
Use JSOUP which extracts datas from website and display the result.
Document document = Jsoup.connect(url).get();
// Get the html document title
String title = document.title(); //get title
Elements description = document
.select("meta[name=description]");
// Locate the content attribute
String desc = description.attr("content");
and so on.

Getting info from a website using Jsoup

So I'm making a small app for myself so I can see my earnings for my apps using Jsoup. The code I have works perfectly, it's extracting the text that I'm having trouble with. I looked at the source code for the website and the text that I want to extract is in a div class named "subheading".
<div class="subheading">
Total revenue: $1.17
Reports
</div>
This is what the div class looks like. Now I want to extract the piece that says "Total revenue: $1.17". So in my code I put
Elements elements = document.select("div.subheading");
When I run the app, it doesn't crash, it just shows up blank. I know my code works though because I put "body" into the document.select(); and the entire body showed up. Does anyone know why nothing is showing up when I use "div.subheading"? Thanks for your help!
Try this
Document doc = Jsoup.parse(html);
Elements elements = doc.select("div.subheading");
String data = elements.text();
Log.i(".........",""+data);

Categories

Resources