Posts

Scrape Facebook fanpage without API and get HTML content.

Hello there, the code below can be used to scrape any Facebook fanpage using CURL and there is no API credentials needed. Of course the fanpage has to be public as most are. <?php $fanPageName = "DisneyTheLionKing" ; $ch = curl_init ( "http://www.facebook.com/" . $fanPageName ) ; curl_setopt ( $ch , CURLOPT_POST , false ) ; curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ch , CURLOPT_USERAGENT , "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7" ) ; curl_setopt ( $ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true ) ; $data = curl_exec ( $ch ) ; echo htmlentities ( $data ) ; ------------------- Output - Not everything pasted here but just to show you. <!DOCTYPE html> <html lang="en" id="facebook" class="no_js"> <head><meta charset="utf-8" /><meta name=&q

Wordpress - Upload multiple files using wp_handle_upload

Image
We are going to use Ajax and PHP to perform multiple file uploads in a wordpress plugin. jQuery Ajax code. To send files. $ ( "#button_id" ) . click ( function ( e ) { e . preventDefault ( ) ; var filedata = document . getElementById ( "inputGroupFiles" ) , formdata = false ; if ( window . FormData ) { formdata = new FormData ( ) ; } var len = filedata . files . length , img , reader , file ; for ( var i = 0 ; i < len ; i + + ) { file = filedata . files [ i ] ; if ( formdata ) { formdata . append ( "file[]" , file ) ; } } formdata . append ( 'action' , 'my_action_upload_logos' ) ; jQuery . ajax ( { url : '<?php echo admin_url(' admin - ajax . php '); ?>' , type : 'post' , contentType : false , processData : false , data : formdata

Tkinter menu button example

Below is Python Tkinter menu button and submenu example. from tkinter import * root = Tk ( ) def random ( ) : print ( "this is a statement" ) mainMenu = Menu ( root ) root . configure ( menu = mainMenu ) subMenu = Menu ( mainMenu ) mainMenu . add_cascade ( label = "File" , menu = subMenu ) subMenu . add_command ( label = "Random Func" , command = random ) subMenu . add_command ( label = "New File" , command = random ) subMenu . add_separator ( ) subMenu . add_command ( label = "Supercalarfragilistic" , command = random ) root . mainloop ( )

Python Tkinter example

Image
This example demonstrates Python Tkinter GUI example. The code fetches weather information from URL, based on the location that is entered. You can get your API key from Openweathermap . Note: Make sure you included a background image in the path. In this case mine is called sky.jpg. import tkinter as tk from tkinter import font import PIL . Image import PIL . ImageTk import requests API_KEY = 'INSERT API KEY' # TODO insert API key from Openweathermap.com #functions def test_function ( entry ) : print ( "button clicked" , entry ) def format_response ( weather ) : try : name = weather [ 'name' ] description = weather [ 'weather' ] [ 0 ] [ 'description' ] temperature = weather [ 'main' ] [ 'temp' ] final_str = 'City: %s \n Conditions: %s \n Temperature (F): %s' % ( name , description , temperature ) except : final_str = 'There wa

Blender Python Examples

Image
Blender Python Generate 50 cubes at random positions. import bpy from random import randint for i in range ( 50 ) : bpy . ops . mesh . primitive_cube_add ( location = [ randint ( - 10 , 10 ) for axis in 'xyz' ] ) Generate cubes that follow a sin curve. import bpy from math import sin for i in range ( 50 ) : x , y , z = 0 , i , sin ( i ) bpy . ops . mesh . primitive_cube_add ( location = [ x , y , z ] )

Python Parse XML

Below code shows how to parse an XML document in Python. XML document simplexml.xml < ?xml version = "1.0" encoding = "UTF-8" ? > < person > < firstname > Joe < / firstname > < lastname > Marini < / lastname > < home > Seattle < / home > < skill name = "JavaScript" / > < skill name = "Python" / > < skill name = "C#" / > < skill name = "HTML" / > < / person > Python XML parser code # # Python parse xml # import xml . dom . minidom def main ( ) : # use the parse() function to load and parse an XML file doc = xml . dom . minidom . parse ( "samplexml.xml" ) # print out the document node and the name of the first child tag print ( doc . nodeName ) print ( doc . firstChild . tagName ) # get a list of XML tags from the document and print each one skills = doc . getElementsByTagN

Python Parse HTML

How to parse HTML using Python and HTMLparser library. # # Python parse HTML # from html . parser import HTMLParser class AnHTMLParser ( HTMLParser ) : def handle_comment ( self , data ) : print ( "Encountered comment: " , data ) pos = self . getpos ( ) print ( " \t At line: " , pos [ 0 ] , " position " , pos [ 1 ] ) def main ( ) : # instantiate the parser and feed it some HTML parser = AnHTMLParser ( ) f = open ( "samplehtml.html" ) if f . mode == 'r' : contents = f . read ( ) print ( contents ) parser . feed ( contents ) if __name__ == "__main__" : main ( ) ; -------------------------------------------------- #Output <!DOCTYPE html> <html lang="en">   <head>     <meta charset="utf-8" />     <title>Sample HTML Document</title>     <meta name="description" content="