How to extract specific details like name and price of a product from Amazon platform using simple html DOM parser. for example: (product-image, name and price).
$httpClient = new \GuzzleHttp\Client();
$response = $httpClient->get('https://www.floridaleagueofcities.com/research-resources/municipal-directory/');
$htmlString = (string) $response->getBody();
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($htmlString);
$xpath = new DOMXPath($doc);
$titles = $xpath->evaluate('//div[#class="accordion-body"]//ul//li/a');
Related
I am using the evernote API to search for notes. I would like to know how to search for the notes only within a given stack.
At the moment I have the code below:
$client = new \Evernote\Client(config('app.evernote_token'), false);
$search = new \Evernote\Model\Search('ftp');
$notebook = null;
$scope = \Evernote\Client::SEARCH_SCOPE_NONE;
$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
$maxResult = 50;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order,
$maxResult);
print_r($results);
Resolved as follows:
$search = new \Evernote\Model\Search('stack:"Palavra-chave"');
I'm using the Contact Form 7 plugin for the user to generate a pdf based on submitted (by the form) and server provided data.
I'd like to also show a "preview" after submission so I need to pass the custom fields to the client in order to get them in some js file.
This is what I have:
plugin rendering the pdf:
<?php
add_action('wpcf7_before_send_mail', 'generate_pdf');
function generate_pdf($wpcf7) {
$file_uri = 'fpdf/fpdf.php';
require_once($file_uri);
/* PDF file initialization */
$pdf = new FPDF();
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','B',12);
$today_date = "California, " . date("d F Y");
$pdf->Cell(0, 10, $today_date, 0, 1, 'R');
$name = $data['your-name'];
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$pdf->Output(wp_upload_dir()['basedir'] . '/' . $name . '.pdf', 'F');
$wpcf7['custom_field'] = 'CUSTOM VALUE';
return $wpcf7;
}
?>
javascript file called on form submit:
$('.wpcf7-submit').on('click', function (e) {
var data = $('form').serializeArray();
var cleaned_data = {};
for (item in data) {
var name = data[item]['name'];
if (name[0] != '_'){
cleaned_data[name] = data[item]['value'];
}
}
var testInput = cleaned_data["your-name"];
})(jQuery);
In this last code I'd like to get the values passed by the php script, but I don't know how to do it.
Assuming that the PDF generation function is in functions.php and that you've enqueued the js, what you're looking to do is localization. You can read more about it here: Localize scripts
I have this code that creates a new Image based on a new file added to the filesystem but not yet in the DB:
$image = Image::create();
$image->Filename = 'assets/Art/e3434cc7-d348-491a-9dc8-325af3d9086d.jpg';
$image->write();
$images = Image::get();
$image = $images->last();
$vd = new ViewableData();
$ad = new ArrayData(array(
'Image' => $image
));
$strHTML = $vd->customise($ad)->renderWith('Art');
Art.ss contains only $Image.SetWidth(100)
Ignoring the fact the query doesn't look up by ID or whatever... why is the image only rendered into $strHTML if I retrieve the image from the DB after creating? If I delete the code below, $strHTML is empty:
$images = Image::get();
$image = $images->last();
There is a setter available so using that alone may help, but you also may need to assign the ID of the parent folder to the object:
$pFolder = Folder::find_or_make('Art');
if ($pFolder) {
$image->setParentID($pFolder->ID);
$image->setFilename('assets/Art/e3434cc7-d348-491a-9dc8-325af3d9086d.jpg');
}
I'm trying to extract Vehicle ID with this code:
$client = new Client();
$request = $client->get('http://www.truck1.eu/_TEN_auto_1522980_Truck_Chassis_MAN_TGA_18_320_BL_Platou_9_80m_lang_manuelles_Getriebe_Euro_4_Motor.html', ['allow_redirects' => false]);
$html = $request->getBody(true);
$crawler = new Crawler();
$crawler->addContent($html);
print $crawler->filterXPath('//*[#id="content"]/div/div[2]/table/tbody/tr[2]/td')->text();
But for some reason i can't get this working. I'm using Guzzle and DomCrawler from Symfony.
Try this XPath to grab the td next to the th containing the 'Vehicle ID' label (and to avoid some unnecessary ancestral dependencies):
//td[preceding-sibling::th = 'Vehicle ID']
I'm starting using Elastica with my Symfony app but I'm stuck to add a filter.
The following code works well, it search by name, slug, agglomeration and then add a geoloc filter. I want to add a "specialty" filter to remove all results which do not correspond to that filter/ have that specialty but I've no idea how to do that.
$nameQuery = new \Elastica_Query_Text();
$nameQuery->setFieldQuery('name', $name);
$slugQuery = new \Elastica_Query_Text();
$slugQuery->setFieldQuery('slug', $name);
$agglomerationQuery = new \Elastica_Query_Text();
$agglomerationQuery->setFieldQuery('agglomeration', $agglomeration);
$boolQuery = new \Elastica_Query_Bool();
$boolQuery->addShould($nameQuery);
$boolQuery->addShould($slugQuery);
$boolQuery->addShould($agglomerationQuery);
//todo add filter by speciality
if($latitude != null) {
$geoFilter = new \Elastica_Filter_GeoDistance('location', $latitude, $longitude, '3km');
$boolQuery = new \Elastica_Query_Filtered($boolQuery, $geoFilter);
}
return $this->find($boolQuery);