views:

42

answers:

4

Hi,

I am scraping a website with HTML with php that retrieves a page and removes certain elements to only show a photo gallery. It works flawlessly for every browser BUT any version of IE (typical ;)). We can fix the problem by rewriting the .css file, but we cannot implement it into the head of the php as this will be overwritten by the .css file from the websites server. How would we go about hosting our own version of the .css file so that our website will be displayed using OUR version? Would be swap something out with a filter?

Cheers!

+1  A: 

Just add another CSS header and mark your styles as !important to override the original ones?

Robus
It would just have to be included after theirs.
Alex JL
You could also put all your content in a `<div class='mycontent'>' and then prefix your CSS selectors with `.mycontent`. It's a bit of a hack, but it can work surprisingly well.
staticsan
+3  A: 

If you're already scrapping the website, why not just use PHP to omit their CSS file and write your own in its place? Alternatively, you could write your own CSS file just below their's in the <head> so it overwrote their styles.

Pat
Right, if you add your CSS file below theirs, it can override any styles defined in the earlier CSS file.
Alex JL
You would need to ensure your CSS and the scraped sites css do not conflict.
cocacola09
+4  A: 

You do realize that it may not really be a scraping problem? It's sounds like a straightforward page display problem.

Worrying about scraping might be a red herring. After you have scraped you have some HTML (and possibly some CSS) ... does that validate at W3C? I realize that is no guarantee, but it is an indicator (I know that IE doesn't always display valid pages properly, but sometimes it's a "gotcha" when other browsers seem to display invalid HTML/CSS properly).

If it's valid then maybe you should look back at your scraping. If you already removes certain elements to only show a photo gallery then maybe you can also remove the CSS from the HTML header (or wherever) and reaplce it with your own?

LeonixSolutions
Yep, IE is way more touchy than other browsers about malformed HTML. Strict, you could say - it's actually helped me catch a lot of errors!
Alex JL
Great call, Leonix. There's so many exotic solutions on SO that could be accomplished with simple, clean, validated code instead. Just imagine if we channeled all that extra energy spent into a single project....such as eradicating IE....
bpeterson76
+2  A: 

This is just another thing to check, but if one of the elements you're removing is comments, you could unwittingly be pulling out ie only stylesheets that are between conditional comments. Another thing to look at is paths. Maybe one of their stylesheets has a relative path that you can't call from your server. You would need to make that an absolute path for it to work.

Really, you should probably take a close look at the source of the original page and your formatted source side by side. You could be pulling out something that's should be left in.

You ask how you could remove their css... you do it the same way you remove the other elements you're pulling out. Just pull out style tags and tags that link to stylesheets.

Aside from that I would just write some styles to fix it and stick it them anywhere after the existing css is called. (Like every one else here mentioned)

Syntax Error