I am stuck with fetching Excel Realtime Data to PHP.
I followed the Link, and converted Excel to Json inside the Excel it self.
https://www.youtube.com/watch?v=qeFHOe-97fw
Now i want to read Particular Cell Value with PHP using Macro (why Macro? : Which will reduce Saving Excel every second).
I found some solution on that, but some how it's not working with me.
Reference Tried: How can I send an HTTP POST request to a server from Excel using VBA?
Can i See Data? (Print or Echo)?
Code: PHP file:
<?php
$excelCellA1Value = $_GET["variable"];
echo $excelCellA1Value;
//$data=$excelCellA1Value;
//echo $data;
?>
VBA File:
Sub PostData()
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1"
url = "http://localhost:81/array/post.php?variable="
objHTTP.Open "POST", url, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send (Cells(18, 2).Value)
RunEveryTwoMinutes
End Sub
My Question is: How can i read a specific Cell Value with PHP "Real Time" as my Value is refreshing every milliseconds.
Or any Possible way to read realtime data?
Regards
Hardik
Related
Having issues using regex to grab HTML contained in a certain span.
Trying to get it to get safeytrfyh is available! on NameMC.com to make a fast checker that will check a pre-specified list if usernames are available instead of constantly typing in the username and clicking check.
An example page you guys can use is https://namemc.com/u/safeytrfyh
Im using cURL for this:
<?php
//Urls to scrape from.
$URLs = array();
$URLs[] = 'https://namemc.com/u/safeytrfyh';
$working = '';
//Curl scraper.
foreach($URLs as $URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
$accounts = array();
preg_match_all('#<div><span[^>]*>(.*?)</span></div>#',$page,$accounts);
foreach($accounts[0] as $account){
$working .= ''.$account.''. PHP_EOL . '';
}
}
//Put the scraped check into the new .txt file.
file_put_contents('accounts.txt', $working, FILE_APPEND);
?>
The usually simpler / less efficient approach is typically traversing the HTML structure with a neat frontend, such as QueryPath etc. qp($html)->find(".alert-danger .alert-link")->text(). Albeit that actually looks less reliable for the concrete task.
Now if for some reason you don't want to look at the HTML source, and adapt your regex, or don't know how placeholders work; then a simpler alternative is just matching for raw text:
$text = strip_tags($html);
preg_match_all("/(\w+) \s+ is \s+ available/x", $text, $matches);
Where \w+ stands for word characters, \s+ for spaces, and /x for readability.
You can convert page in to DOM object can get what ever you want as:
<?php
$url = "http://stackoverflow.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // if page is https (use if you are using local host)
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch); // Can echo to check page
$dom = new DOMDocument();
#$dom->loadHTML($page);
$xpath = new DOMXPath( $dom );
$query21 = '//div[#id="question-mini-list"]//h3//a[#class="question-hyperlink"]' ;
$nodes21 = $xpath->query( $query21 );
$title = "questions.txt";
$file_title = fopen($title, 'w');
foreach( $nodes21 as $node21 )
{
$tit = trim($node21->nodeValue); // HEADING
fwrite($file_title, $tit . "\r\n");
}
?>
OUTPUT as:
I have an araay in one file and i want to find the size of it in another file using “sizeof” , i dont want to use any extra variables?
No Activity found to handle Intent act=android.intent.action.VIEW when trying to play an audio file
Naming a variable dynamically in Ruby
uanble to use Bootstrap Notify with angular js in mvc application
How do I combine a bootstrap carousel with a sidebar menu?
Stop pausing when mouse hover -Full Slider
How to Let Recordset #2 in the Same Position as the Similar Recordset#1
Bash backup script. Read list of files. [OS X]
extracting multiple columns from mt0 in hspice simulations using awk command
Can't invoke *method=* type methods in instance_eval
Couldnt understand the Array behavior in ruby
Could not connect to sql server using msado15.dll in c++
Slick 3.0.0 AutoIncrement Composite Key
Swift Error type 'usersVC' does not conform to protocol 'UITableViewDataSource'
Installation Error Unknown Failure
Is it possible to 'emulate' a regular post that loads a new page in angularjs? or plain java as a backup?
puppet file protocol handle throws Could not evaluate
Hazard of load address in mips
how to post multipal files to a url from jscript?
How to organize the viewmodel of tableview with section in reactiveUI
CQRS with legacy MSSQL database
Should I use Blob storage or Azure VM storage for files?
Copy cell content from a column to another column in matlab
How do I debug a crash on iOS device from a crash log
Combobox in windows phone 8.1 not showing 4th and 5th element in emulator
How to add padding in printing table in F#?
I don't understand the SpriteAccessor class (Universal Tween Engine)
mule reliable pattern with file streaming and JMS
How to tell Faraday to preserve hashbang in site URL?
maven-license-plugin by mycila (replacing license header)
Customise `JOptionPane.YES_NO_OPTION`
AWS: Boto SQS writing isn't saving
Android expandable listview always scrolls down to bottom
Inconsistency in TypeConverter behavior?
Using function as prototype
Adjust width of inline buttons automatically based on parent width
GetWeek of Month, Week starts from Monday
Has anybody tried to recreate UITableViewController with static cells?
Why shows --“cannot pass objects of non-trivially-copyable type”?
Search and update a string in a text file in JAVA
What is Countdown Latch in Java MultiThreading?
Slim Framework with ORM (Eloquent) connect multiple db
Why isn't the frame centred in this GUI program when it is run?
Custom Logout Handler Not Working Grails
Response to post request to AWS “breaks the pipe”, cannot read
how to set focus to a SearchBox control in windows 8.1 store app?
Removing a word from after a string
need to generate css from scss file on windows 8.1 using gruntjs compass
Arduino YUN - complex JSON response
How to use expandable list view in the following scenario
Unique DB entry to the user
R : Save big objects to disk then only load parts of them
What is wrong based on these dbus system bus log files?
NLP Shift reduce parser is throwing null pointer Exception for Sentiment calculation
Excel VBA - Combine Rows with duplicate values, merge cells if different
what's TransactionID and RowID and Roll Point size in InnoDB
File associations in vscode
Difference Between IEnumerable Model and Model
efficient way of passing Data between Matlab functions
Open new Form in same window silverlight app via c#?
Hibernate configuration to create hbm and POJO
FTP Client gives “ECONNREFUSED - Connection refused by server”
Timer in Selective Repeat ARQ
Can TXL be used for code clone detection
MATLAB - Callback after reparenting
Asynchronous execution with datastax mapper
Stopping gobbler threads in blocking reads on Process InputStream
how to get gabor filter image using opencv?
WebView shows source html with loadDataWithBaseURL, not rendered view
git merge forked repo to local repo
Scrapy (Python): Iterating over 'next' page without multiple functions
android:uiOption=“SplitActionBarWhenNarrow” does not work
md5 hash a large file incrementally?
Instagram relationship request endpoint registration issue
cuda calc distance of two points
How to share contents of ListView row on facebook in Android?
how will the socket act when the receiving speed is larger than process speed
cannot see particle (cocos2d-x 3.5 with Particle Designer2)
Couldn't find FoodObject without an ID
CardView and RecyclerView divider behaviour
Verification google play purchase from server side
dyld: Symbol not found: _iconv when using javac to compile on MacOS
R not producing a figure in jupyter (IPython notebook)
Entity Framework 6 update a table and insert into foreign key related tables
I have integrated CLIPS with VC++(MFC), why there are some function does't execute,such as “strcmp”
Using SelectBoxIt in AngularJS Directive
Where is the Google Information Rights Management API?
Open Graph in Laravel 5
CodeIgniter 3 Unable to locate the model you have specified
how to have a static url for shopify oauth?
Use AnnotationReader under namespace
No such .h file or directory(Android, Cocos2d-x, NDK)
Getting total sum of rows and adding and removing rows using knockoutjs
Dynamic default value for Kendo Grid
Ruby's class expression---how is it different from `Class.new`?
socket.emit is not working in mobile chrome (but it works in incognito mode)
I have been looking into an option to send data read from an attached file in an Outlook message, directly to a PHP script that will then insert the date in a nice MySQL database.
The extraction of the file and the splitting of data all ok, but here is the trick...
From the internet (here) I found a nice post by Jeremy Slade who has managed to send some data to a cgi scipt, all good.
So, clever as I thought I was, I thought I could re-write this into dealing with a PHP script.
But then the works stopped.
I have shortened the code to below snippet;
Sub TestURL()
Set xhr = CreateObject("MSXML2.XMLHTTP")
URL = "http://somedomain.com/php/test.php"
data = "someVariable=Test"
With xhr
.Open "POST", URL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send data
End With
End Sub
This should, in theory, open a MSXML2.XMLHTTP request at the given URL and send whatever data with it to the script.
Funny enough, the script is called, but no data is passed ?
I've tried setting the PHP script to both $_GET and $_POST for the [someVariable] element, yet on neither is there any response ?
When I set the PHP to $_GET I matched the VBA MSXML2.XMLHTTP object to "GET" as well and vice versa...
I've tried passing the 'data' variable as argument to the 'function' .send by including it in brackets
i.e.
.send (data)
But this doesn't work either...
I'm a bit at a loss, because the script is called, a dataline is added to the table yet there is not an actual transfer of the 'sent' data ??
I've tried connecting the data string to the URL that is passed to the HTTP object, essentially passing a 'GET' URL to the HTTP object.
i.e.
URL = URL & "?" & data
but to no avail...:-(
The php script works in itself properly, if I pass data directly from the browser
i.e.
http://somedomain.com/php/test.php?someVariable=Test
the data is correctly added and the variable is read...
Can some more enlightened spirits guide me in the right direction ?
20141016 ********** UPDATE **********
Ok, when digging into stuff I found there is also an option to refer to the XmlHttp object as "Microsoft.XmlHttp" ?
Funny enough, when setting the object like that,
i.e.
Set xhr = CreateObject("Microsoft.XMLHTTP")
The code works and the data is added to the table and the .responsText is a success message.
Yet if I return to the original code, I get a PHP error message that tells me that there is an error in my PHP syntax ?? This would imply that the actual 'data' that is being send differs between using "MSXML2.XMLHTTP" and using "Microsoft.XMLHTTP" ???
Have tried to dig out the difference between the two from internet but can't find any post that provides me with a full understanding of the subject ?
Despite the fact that my code now works, I still have the bothering question of not understanding the difference between the two and would appreciate a reply from someone who does :-) As I now have a code that works, but not an understanding of why it works...:-)
Or mroeover not an understanding of why the "MSXML2" option does NOT work...
Much appreciated,
Kindest regards
Martijn
This is not exactly an answer but more like a comment as I lack enough reputation to comment.
The issue can be analyzed using Fiddler which provides details of the requests and responses. I checked the same code as yours in my system with both MSXML2.XMLHTTP and Mirosoft.XMLHTTP objects and found no difference in teh requests. Both of them passed the POST request body containing someVariable=Test to the URL http://somedomain.com/php/test.php.
Here is the raw POST request in both cases:
POST http://somedomain.com/php/test.php HTTP/1.1
Accept: */*
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC LM 8)
Host: somedomain.com
Content-Length: 17
Proxy-Connection: Keep-Alive
Pragma: no-cache
someVariable=Test
And the response from the sample URL provided:
HTTP/1.1 405 Method Not Allowed
Server: nginx/1.7.6
Date: Thu, 08 Jan 2015 15:23:58 GMT
Content-Type: text/html
via: HTTP/1.1 proxy226
Connection: close
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.7.6</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
One question here would be whether the web server in question is expecting further data to be passed by the way of headers (User-Agent, Referer, Cookies etc) or as part of the request body (may be further input elements that are part of the webform)?
I'm working on building a local php page to output the public Company info from Facebook in XML with help from a friend and I am going to create a VBA macro to webcrawl to that page and download the information into my workbook in Excel. However, the input for the company name must be from a cell on the spreadsheet and I don't know how to pass this into the request I am sending to the Graph API besides writing that straight into the PHP file. How do I make VBA pass the value from the spreadsheet cell (eg. A1=Hilton) to PHP to replace the hard-coded company name so that I can use this for any company?
Clarification of Requirements:
VBA Reads company name from cell A1
VBA sends company name as variable to PHP
PHP post to Graph API using the company name sent from VBA
VBA Macro crawls local PHP page and downloads the XML output into workbook
You could use a VBA macro like I created below. In my example I made the macro tied to a button click
Sub Button1_Click()
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://www.yourdomain.com/page.php?variable=" & ActiveWorkbook.Worksheets(1).Range("A1").Value
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
End Sub
Your PHP script on your server would look like
<?php
$excelCellA1Value = $_GET["variable"];
//Work magic here such as posting to Facebook API
//TO DO: Profit!
?>
How to Get a html page content using Inet in vb6 and put the content in a TextBox ?
Try sample code in Retrieving Data Using Visual Basic article.
Try this:
Function GetHTMLCode(Optional strURL As String) As String
Dim objHttp As Object, strText As String
Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
objHttp.Open "GET", strURL, False
objHttp.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHttp.Send ("")
strText = objHttp.responseText
Set objHttp = Nothing
GetHTMLCode = strText
End Function
OK?)
You can also use vb6 webbrowser control.Using this you can get html page and of course according to html tag,input id etc.
I have a PHP server running on Apache, I get lots of request looks like this,
10.1.1.211 - - [02/Sep/2010:16:14:31 -0400] "GET /request?_=1283458471913&action=get_list HTTP/1.1" 200 547 0 "http://www.example.com/request" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)" 28632 15602
The _ parameter is mysteriously added to the request. I am trying to find out who is doing that.
There is a NetScaler running in front of Apache.
jQuery adds a parameter like that to get around IE's caching.
edit:
it only adds it for get requests, and only if the option cache is false:
cache: false
It could be the JQuery CacheBuster parameter.
Resources :
[jQuery] GData JSON queries "Invalid query parameters:_"
[jQuery] Turn off Cache Busting in $.getScript
Cache-busting
Probably it's a dummy parameter added by the reverse proxy to force non-cached content to be served.
1283458471913 is a unix timestamp in ms, probably a bot/proxy making sure that they get a fresh page and not a cached version.
Could also be jQuery which would cause this for AJAX request of you have the nocache attribute set to true.
if ( s.cache === false && type == "GET" ) {
var ts = now();
// try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2″);
// if nothing was replaced, add timestamp to the end
s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
}
Ajax tools, like jQuery, is able to ask the browser not to cache the requested result, so every request from the loaded web page will travel to web server and get the newest response.
In order to achieve that, set cache flag as false, then an additional query parameter, like _=1234567890, is appended into the request URL. Of course the number is always changing, so the browser thinks it as a brand-new request and won't provide any cached things.