Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 jQuery

views
     
sunsuron
post Oct 30 2009, 10:38 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>mumeichan</title>

</head>
<body>

<p class="normalname">Hello</p>
<p class="normalname">World</p>

<div id="bla"></div>


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

//$('#bla').html($('.normalname').text()); // get only the text and put them inside the DIV
$('.normalname').clone().prependTo('#bla'); // duplicate all element with the class 'normalname' and put them inside the DIV

</script>
</body>
</html>

sunsuron
post Oct 31 2009, 01:11 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



If you need web scraping script, it will require mo lines of codes. Why do you need to gather all the username?
sunsuron
post Oct 31 2009, 10:33 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



With GM, this is very easy. The only reason it will failed is because there is nothing returned by your jQuery selector. I did a quick test with GM version 0.8 on this very page and it return what I expect.

1. copy paste the jQuery core library into your GM script.
2. copy paste code below
» Click to show Spoiler - click again to hide... «


The code above will try to scan all occurrence of 'span.normalname a' which translates 'Find all <span> with have the class value of normalname and <a> as their child'. I will get an alert contains all the user names in this page. I did not test in other pages.

user posted image

sunsuron
post Nov 1 2009, 08:54 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



Dealing with multiple class can be bit tricky but luckily jQuery provide the attr() function. We can find all the elements with specific classes with this function. Here is an example:

» Click to show Spoiler - click again to hide... «

sunsuron
post Nov 2 2009, 09:32 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



I declare a variable called collection to store array of something (in this case, usernames). It is the same effect with:

CODE
var collection = new Array();


It's just a syntax shortcut.

 

Change to:
| Lo-Fi Version
0.0173sec    0.58    6 queries    GZIP Disabled
Time is now: 7th December 2025 - 05:59 PM