How I web-scrape the data a website that I need perform some action in website before the data I need via Flutter? - flutter

The website that I would like to scrape
Before scraping the data I need first I must choose departure, arrival and date then I must clicked the green buton then I can reach the data I would like to scrape.
How I can perform these actions in website via Flutter. Then I will use these datas in the Flutter app.
I tried to scrape via import http.dart and parser.dart libraries but I couldn't. I am beginner in coding and Flutter.

Hey found a article which will help you do this.
Follow :
https://morioh.com/p/b7b4aa4d696e
Kudos to Morioh for the detailed step by step article.
Concern : this might be outdated package as there is no update since past one year.

You maybe need the dart:html in all app scope , but this file are limited on the web (or You need to do something different on the web than on an Android device!).
you can create 3 file and to handle this mode.
file web.dart :
import 'dart:html' as html;
void webScrap() {
// blablabla webScrap in web
}
String cookie = "";
file native.dart :
void webScrap() {
// blablabla webScrap in native
}
String cookie = "";
file switch_native_web.dart :
import 'native.dart' if (dart.library.html) 'web.dart' as switch_value;
class SwitchNativeWeb {
static String cookie = switch_value.cookie;
static void webScrap() {
switch_value.webScrap();
}
}
But i suggest to you , see this example for web scraping in flutter .
Gist full Snippets: Gist.Github.com
Repository : Github.com

Related

Flutter Web: Correct way of keeping user logged in/Remember me functionality

I am working on a web app in which, I want to keep user logged in during page refresh or even if the tab is no longer exist just like youtube/gmail web app. How to create that ???
In flutter mobile for android/ios we can used shared preferences which uses shared preferences for android and NSUserDefaults for ios to make that functionality. But in the case of Flutter web we can't store user creds into local/ session storage or even in cookies.
I recently started using flutter web so, please guide me on the right path, any link to good resources is much appreciated.
Edited: You can use hivedb packages from pub.dev for safe and high speed storage supporting on web also:
import 'package:hive/hive.dart';
import 'dart:convert';
void main() async {
//Hive.init('somePath') -> not needed in browser
var box = await Hive.openBox('testBox');
box.put('user', json.encode(User(name:'john',password:'pass')));
print('Name: ${box.get('user')}');
}
https://pub.dev/packages/hive
https://docs.hivedb.dev/#/

Redirect URL from local filesystem to internet with browser WebExtension

To summarize the problem, I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet (i.e. clicking the link opens the browser and takes you to file:///page instead of http://domain/page).
Getting these files modified to include the full URL is not an option. My question is almost identical to the question I asked a year and a half ago. The difference is that I need to port my existing extension (made with the Firefox SDK) to the new WebExtensions API for Firefox (same as Chrome extensions).
There are methods available for redirection, such as
browser.webRequest.onBeforeRequest.addListener(
redirect,
{urls:[pattern]},
["blocking"]
);
but that only accepts http:// and https:// URL patterns.
I am currently trying to use the following code:
var id;
browser.tabs.onCreated.addListener( details => id = details.id )
browser.tabs.onUpdated.addListener( (tabId, changeInfo, tab) => {
var url = changeInfo.url;
if (tabId == id && url.includes("file:///")) {
url = url.replace("file:///page", http://domain/page");
browser.tabs.update(
id,
{ url: url }
);
}
});
Unfortunately, I have the same fundamental issue as with my original problem, resulting in the onUpdated listener not firing (or if it does fire, it's not because of a URL change). But regardless of the listener used (e.g. onCreated, onActivated, etc.), I get about:blank for the URL.
I have tried injecting code to change the value of the address bar, but that doesn't seem to work either:
browser.tabs.executeScript( {
code: "window.location.href = window.location.href.replace('file:///', 'http://domain/')"
});
Thanks for any help!
redirectUrl : chrome.extension.getURL("hello.html")
Worked for me

Send user to page on mobile app when clicking email link

I have just started an Ionic 2 mobile app.
I am setting up an update password process where a user can enter their email, click a "send password update email" button which then emails them a link. They can click that link which takes them to a page where they can update their password.
How do I send them a link in their email that when clicked on will open up the app and take them to a specific page?
Even more complicated is that I have a web app also. So if I'm sending them an email, should I show update password on website and update password on mobile app links? Or should I just add a link to the website?
In order to open the mobile app from a link, you need to integrate a cordova plugin called cordova-plugin-customurlscheme. With this plugin you can register a custom url "protocol" that is unique to your app (eg. myAwesomeApp://register?token=123). After installing the plugin with your custom url, clicking on any link starting with myAwesomeApp:// will open your app and also trigger a function hooked on the window object called handleOpenUrl which accepts the url as param. Inside there you can do your routing, depending on the url param.
let self = this;
(<any>window).handleOpenURL = function handleOpenURL(url) {
setTimeout(() => {
if (url && url.indexOf('\register') !== -1) {
let token = URLHelper.getParameterByName(url, 'token');
self.setAsRoot(ConfirmEmailPage, { activationToken: token });
}
}, 0);
};
As for dealing with your web app, what you could do is the following (this is what I am currently doing):
Host online a page (say www.myAwesomeWebsite.com/register?token=123) that checks to see if the user is coming from a mobile device (iOS or Android more specifically). If so on page load redirect them to your myAwesomeApp://register?token=123 link and have a button saying install app from app store with a link to your mobile app. If the user has the app, the app will be opened by the redirect, if they don't they will get an alert saying link cannot be found or sth and after clicking ok they will see the install App from app store button. If the user is not coming from a mobile device, just redirect them to your web app myAwesomeWebApp.com/register?token=123.
Another option is to use a third party service for deep linking like branch
Hope that helps.
EDIT: Since I posted this answer Ionic team has come with their own plugin for deep linking that kind of simplifies some of the hooking up inside your app. Their detailed blog post can be found here. In essence you install their plugin:
cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=ionichats --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=ionic-hats.com
and then hook to it like so:
import {Component, ViewChild} from '#angular/core';
import {Platform, Nav, ionicBootstrap} from 'ionic-angular';
import {Deeplinks} from 'ionic-native';
import {AboutPage} from './pages/about/about';
import {HatDetailPage} from './pages/hat/hat';
#Component({
template: '<ion-nav [root]="rootPage"></ion-nav>',
})
class MyApp {
#ViewChild(Nav) nav:Nav;
constructor(private _platform: Platform) {}
ngAfterViewInit() {
this._platform.ready().then(() => {
Deeplinks.routeWithNavController(this.nav, {
'/about-us': AboutPage,
'/hats/:hatId': HatDetailPage
});
});
}
});
ionicBootstrap(MyApp);
Note that although this improves the plugin interfacing a bit, it does not change the fact that you have to use some other mechanism to handle deep links in conjunction with your web app.

Getting error unsupported_response_type

I am working on login with google functionality with $cordovaOauth.google plugin. But I am getting unsupported_response_type error.
$cordovaOauth.google("MY_APP_ID", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function (result) {
console.log(JSON.stringify(result));
alert(JSON.stringify(result));
$scope.gdata = result;
}, function (error) {
console.log(error);
});
Where I am making mistake !?
Yes because $cordovaOauth plugin loading webview so you must need web clientID from Google API. And that will not work for ionic ( Mobile app ) so you need to do following things.
First
You need to use schema for your app to give internal URL like google:// or twitter://
Reference : http://mcgivery.com/using-custom-url-schemes-ionic-framework-app/
and provide that custom URL in Google redirect url ( This is not working all time as Google not accept custom URL but you can give it a try ).
Second and Working solution :
You need to create Google app with your app identifier and keytool.
For Android :
https://developers.google.com/identity/sign-in/android/start follow step second and provide your app name and unique identifier ( i.e dipesh.cool.com )
For iOS : 
https://developers.google.com/mobile/add?platform=ios&cntapi=signin
same information as mentioned for android.
Then you need to get REVERSED_CLIENT_ID value from the config file which download will be available once you are done with above two steps ( you can grab it from iOS config file it is easy to find from that file ).
And then simply run below command and code and you will have all working.
Command :
cordova plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=GRAB_THIS_FROM_IOS_OR_ANDROID_CONFIG_FILE
Angular code :
$scope.GoogleLogin = function()
{
$scope.loaderShow('Google');
window.plugins.googleplus.login({},function (obj)
{
window.localStorage.setItem('signin', 'Google');
window.localStorage.setItem('g_uid', obj.userId);
window.localStorage.setItem('g_fname', obj.givenName);
window.localStorage.setItem('g_lname', obj.familyName);
window.localStorage.setItem('user_full_name', obj.displayName);
window.localStorage.setItem('g_email', obj.email);
window.localStorage.setItem('gotPdetails', 'false');
$scope.loaderHide();
$state.go('app.dashboard');
},
function (msg)
{
$scope.showAlert('Google signin Error<br/>'+msg);
$scope.loaderHide();
});
}

Sending a file throught a Post with HTTPBuilder in Grails

I am developing a Facebook Application an i wanna send a video file from myServer to Facebbok User`s Timeline. This is the page with the explanation http://developers.facebook.com/blog/post/515/#video_upload but its a PHP code.
My app is on Grails, and im looking in HTTBuilder class but can't find a way to do this.
Do someone know how to do it?
If isnt possible to do this with HTTPBuilder, in my app, i am using Spring Social Facebook Plugin on Grais
I found the interface MediaOperations but i dont know how to use this interface and use the method postVideo to upload a Video.
Thanks!
Will try to help a bit. You may use MediaOperations interface for this operation. Spring Social Facebook Plugin configures a service called Facebook for you. You can use it via dependency injection.
Here is a simple code example:
import org.springframework.social.facebook.api.Facebook
class FacebookService {
Facebook facebook
def uploadVideo(String videoFileName, String title, String description) {
try {
def videoResource = new FileSystemResource(videoFileName)
facebook.mediaOperations().postVideo(videoResource, title, description)
return true
}
catch (Exception e) {
log.error("Error to upload video to facebook", e)
return false
}
}
}
The video is loaded from the file in the FS by specified file path/name from videoFileName variable. This means, user need to upload the video first, and code should save it to some file in FS first, then upload. Usually this is the best case, as video files are large. Maybe there is a sense to upload the video to facebook in separate thread and don't give the user to wait.