Hi a have 100 such elements * 40 files = 4000 elements.
I want to extract src and href from each element and write it to array to simply send it to database
<a class="market_listing_row_link" href="http://steamcommunity.com/market/listings/730/FAMAS%20%7C%20Colony%20%28Minimal%20Wear%29" id="resultlink_99">
<div class="market_listing_row market_recent_listing_row market_listing_searchresult" id="result_99">
<img id="result_99_image" src="http://steamcommunity-a.akamaihd.net/economy/image/fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZYMUrsm1j-9xgEObwgfEh_nvjlWhNzZCveCDfIBj98xqodQ2CZknz59Ne60Iwh0fTvREaFdWco39RrlByIN5M5kXMP49bhWKA3utIrGYLl-M4pJH5PRWaLSNFz5ux1pg_dbeZyPoyvui3i6PnBKBUQvkKsHsA/62fx62f" style="border-color: #D2D2D2;" class="market_listing_item_img" alt="" />
<div class="market_listing_right_cell market_listing_their_price">
<span class="market_table_value">
Starting at:<br/>
<span style="color:white">$0.05 USD</span>
</span>
<span class="market_arrow_down" style="display: none"></span>
<span class="market_arrow_up" style="display: none"></span>
</div>
<div class="market_listing_right_cell market_listing_num_listings">
<span class="market_table_value">
<span class="market_listing_num_listings_qty">6,191</span>
</span>
</div>
<div class="market_listing_item_name_block">
<span id="result_99_name" class="market_listing_item_name" style="color: #D2D2D2;">FAMAS | Colony (Minimal Wear)</span>
<br/>
<span class="market_listing_game_name">Counter-Strike: Global Offensive</span>
</div>
</div>
</a>
You could try using Simple HTML Dom: http://simplehtmldom.sourceforge.net/
It will let you go through the HTML using the DOM instead of having to manually parse through everything.
Related
I have a html code with many html tables. I want to extract links from specific one which has specific div above.
Here's my sample code:
<div class="boxuniwersal_header">Table 1</div>
<img src="img/boxuniwersal_top.gif" width="210" height="18" alt="" style="margin-top: 5px" />
<div class="boxuniwersal_content">
<div class="boxuniwersal_subcontent">
<div class='menu_m1'><table cellpadding="3"><tr><td><img src="some.jpg" width="45" /></td><td>Some text</td></tr></table></div>
<br />
</div>
</div>
<!-- /box -->
<!-- box -->
<div class="boxuniwersal_header">Table 2</div>
<img src="img/boxuniwersal_top.gif" width="210" height="18" alt="" style="margin-top: 5px" />
<div class="boxuniwersal_content">
<div class="boxuniwersal_subcontent">
<div class='menu_m1'><table cellpadding="3"><tr><td><img src="some2.jpg" width="45" /></td><td>Some text2</td></tr></table></div>
<br />
</div>
</div>
$domXPath = new DOMXPath($domDocument);
$results = $domXPath->query("//div/div/table/tr/td/a|//table//tr/td//a"); //querying domdocument
foreach($results as $result)
{
$links[]=$result->getAttribute("href");
}
This code returns all links. I want to grab only links from Table1. Is it possible?
Your main problem is just tuning the XPath expression to select the right XML.
If you change your XPath to
//div[text()="Table 1"]/following-sibling::div[1]//table//a
What this does is first find the <div> element whose text is the one your after.
The following-sibling::div[1] part will look at the first <div> element at the same level as the <div> element already selected (this is the one where the <table> is).
The last part just looks for all <a> elements within the enclosing <table>.
I have problem with some angular things. I'm trying to set recursive dive with some info with some hintshow (tooltip).
The problem is all information show fine exclusive the hintshow. Added the screen show + some code. The data saved in {{x.who_liked}} as string, for example
"wyd3x, someoneXD, Shohamiko, guymaster, HUBHVNKL, Rauli, Matk, gal350"
<div ng-repeat="x in names | startFrom:currentPage*pageSize | limitTo:pageSize">
<div class="post">
<div class="posterDetails">
{{x.username}}</br>
פירסם ב<?php echo timeAgo("{{x.date}}"); ?>
<div ng-switch on="x.user_id">
<div ng-switch-when="<?=$_SESSION['id']?>">
<?php
echo " <a style='color:red;' href=\"?page=feeds&id={{x.id}}&delete\">(מחק סטטוס)</a>";
?>
</div>
</div>
</div>
<div class="postContent" ng-bind-html="x.msg | unsafe"></div>
<div class="options" style="text-align: right;padding: 5px;">
<div id="like" style="display:inline-block">
<img src="images/{{x.liked}}" post_id={{x.id}} ng-click="like(x)"> {{x.likes}} <div class="liked" onMouseover="showhint('{{x.who_liked}}', this)" style="display:inline-block">אהבו</div>
</div>
<div id="report" ng-click="report(x)" style="cursor: pointer; display:inline-block">
<img src="images/icons/vlag.png"> דווח
</div>
</div>
</div>
current station
tooltip: http://dynamicdrive.com/dynamicindex16/showhint.htm
You shouldn't be using {{}} interpolation inside your onMouseover directive.It should be onMouseover="showhint(x.who_liked, this)"
or
Angular solution
You can fix it like this :
ng-mouseover="showhint(x.who_liked,this)"
Instead of onMouseover , you can use ng-mouseover.
For better understanding , see this fiddle
I have HTML code like this:
<li class="recipe-ingredient">
<span class="recipe-ingredient-quantity-unit">
<span data-original="" data-fraction="" data-normalized="0" class="recipe-ingredient-quantity recipe-ingredient-quantity"></span>
<span data-original="" class="recipe-ingredient-unit recipe-ingredient-unit"></span>
</span>
<span class="recipe-ingredient-name recipe-ingredient-name">water</span>
<span class="recipe-ingredient-notes recipe-ingredient-notes">For Kneading</span>
</li>
Using preg_replace, I want to wrap first set of <span> within one <div> and last two sets of <span> within another <div>, so my final outcome would be:
<li class="recipe-ingredient">
<div class="ing-qt-unit">
<span class="recipe-ingredient-quantity-unit">
<span data-original="" data-fraction="" data-normalized="0" class="recipe-ingredient-quantity recipe-ingredient-quantity"></span>
<span data-original="" class="recipe-ingredient-unit recipe-ingredient-unit"></span>
</span>
</div>
<div class="ing-name-notes">
<span class="recipe-ingredient-name recipe-ingredient-name">water</span>
<span class="recipe-ingredient-notes recipe-ingredient-notes">For Kneading</span>
</div>
</li>
This first one should catch the first set:
<span class[^>]+>(?:[^<]+<[^>]+>[^<]*<[^>]+>)*[^<]*</span>
And this one should catch the second set:
<span class[^>]+>(?:[^<]*<[^>]+>[^<]+<[^>]+>)*[^<]*</span>
Use it like this to avoid escaping:
$re = "#<span class[^>]+>(?:[^<]*<[^>]+>[^<]+<[^>]+>)*[^<]*</span>#im";
The replacement should be something like "<div class="ing-name-notes">$0</div>".
Here is a same of code I have extracted from a webpage...
<div class="user-details-narrow">
<div class="profileheadtitle">
<span class=" headline txtBlue size15">
Profession
</span>
</div>
<div class="profileheadcontent-narrow">
<span class="txtGrey size15">
administration
</span>
</div>
</div>
When displayed on the webpage it shows as "Profession administration". What I want to do is extract the profession, in this case "administration". However, it's not as simple as it might seem because this piece of code is repeated many times for various other questions, such as
<div class="user-details-narrow">
<div class="profileheadtitle">
<span class=" headline txtBlue size15">
Industry
</span>
</div>
<div class="profileheadcontent-narrow">
<span class="txtGrey size15">
banking
</span>
</div>
</div>
Any ideas on a good solution?
Please, do not use regular expressions for getting node values from a page.
PHP have a very nice class named DOMDocument. You can just fetch a page as DOMDocument:
$dom = new DOMDocument;
$dom->loadURL("http://test.de/page.html");
$finder = new DomXPath($doc);
$spaner = $finder->query("//*[contains(#class, 'size15')]");
echo $spaner->item(0)->nodeValue . "/" . $spaner->item(1)->nodeValue;
I have the following html code:
<div class="media row-fluid">
<div class="span3">
<div class="widget">
<div class="well">
<div class="view">
<img src="img/demo/media/1.png" alt="" />
</div>
<div class="item-info">
Title 1
<p>Info.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
<div class="widget">
<div class="well">
<div class="view">
<img src="img/demo/media/2.png" alt="" />
</div>
<div class="item-info">
This is another title
<p>Some info and details go here.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
</div>
Which basically alternates between a span class with the widget class, and then the widget class without the span3 class.
What I wanted to know was if there was a way to have php "echo" or populate the details for and details under the "item-info" class. Would I need to use a foreach statement to get this done? I would be storing the information in a mysql database, and while I can get it to fill in the info one by one (repeatedly entering the and echoing out each image and item title) it's not practical when the content needed to be displayed is over 15 different items. I'm not well versed in foreach statements so I could definitely use some help on it.
If someone could help me perhaps structure a php script so that it can automatically output the html based on the number individual items in the database, that'd be greatly appreciated!
I'm wondering if the html + php (not including the foreach) would look like this:
<div class="span3">
<div class="widget">
<div class="well">
<div class="view">
<img src="img/<? $file ?>" alt="" />
</div>
<div class="item-info">
<?$title?>
<p>Info.</p>
<p class="item-buttons">
<i class="icon-pencil"></i>
<i class="icon-trash"></i>
</p>
</div>
</div>
</div>
EDIT:
I wanted to add some more information. The items populated would be based on a type of subscription - which will be managed by a group id.
I was initially going to use <? (if $_SESSION['group_id']==1)>
echo <div class="item-info">
$title
<p>$info</p>
</div>
so that only the subscribed items would populate. But, I would need it to iterate through all the items for group1 table and list it. Currently I know that I can do
<? (if $_SESSION['group_id']==1)
while ($row=mysql_fetch_assoc($sqlItem))
{
$itemInfo = $row['info'];
$image = $row['image'];
$title = $row['title'];
$url = $row['url'];
};
>
$sqlItem for now can only be assigned one thing (manually - as in: $sqlItem = '123'), unless I iterate through which is what I'm trying to figure out.
Just read that 'mysql_fetch_assoc' is being depreciated with 5.5, here is the new way and looks better, easier I think.. Hope this helps, was updated today.
I hope this helps http://php.net/manual/en/mysqli-stmt.fetch.php
replace the printf with echo '//then your html stuff
This will iterate through the rows in your database until their are no more matching records.
shouldn't a while be enough? It depends on the structure of your database and website (we didn't need so much HTML I think. Some more PHP maybe). Hope this helps.