Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Tumblr.com -> cURL logowanie
kamykthm
post 2.09.2013, 10:57:11
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 12.08.2009

Ostrzeżenie: (0%)
-----


Witam,
ktoś robił może logowanie do Tumblra via curl? Da rade zrobić logowanie via curl czy tylko przez api Tumblra?
Z góry dzieki za odp.
Go to the top of the page
+Quote Post
jackraymund
post 2.09.2013, 11:24:03
Post #2





Grupa: Zarejestrowani
Postów: 217
Pomógł: 21
Dołączył: 10.06.2011
Skąd: Głogów

Ostrzeżenie: (0%)
-----


nic prostszego
wchodzisz na
https://www.tumblr.com/login GET
pobierasz dane
  1. <div class="form_row_hidden"><input type="hidden" value="login" name="context"></input><input type="hidden" value="" name="follow"></input><input type="hidden" value="https://www.tumblr.com/login" name="http_referer"></input><input type="hidden" value="!1231378117324|ZocjPLAmcBjZtcF7P35Krtuls" name="form_key"></input><input id="seen_suggestion" type="hidden" value="0" name="seen_suggestion"></input><input id="used_suggestion" type="hidden" value="0" name="used_suggestion"></input></div>


a potem tylko POST na https://www.tumblr.com/login
z wczesniej wyczytanych danych
  1. user%5Bemail%5D=asdf&user%5Bpassword%5D=asdf&tumblelog%5Bname%5D=&user%5Bage%5D=&recaptcha_public_key=6Lf4osISAAAAAJHn-CxSkM9YFNbirusAOEmxqMlZ&recaptcha_response_field=&context=home_signup&follow=&http_referer=https%3A%2F%2Fwww.tumblr.com%2F&form_key=%211231378117316%7CMzSUQp64GQIMz8M9rKYTSzOs3E&seen_suggestion=0&used_suggestion=0




do moderatora, niemam pojecia czemu rozwala strone moj post, php i html powinien scrollbarować

Ten post edytował jackraymund 2.09.2013, 11:25:53


--------------------
Wykonuje zlecenia na pobieranie danych ze stron i różne boty.
Go to the top of the page
+Quote Post
kamykthm
post 2.09.2013, 11:40:21
Post #3





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 12.08.2009

Ostrzeżenie: (0%)
-----


Chcesz dane pobierac przez dom'a?
Ty a możę jak Ci się nudzi to napisz skrypcik logowania arrowheadsmiley.png baaasmiley.gif
Go to the top of the page
+Quote Post
jackraymund
post 4.09.2013, 15:57:41
Post #4





Grupa: Zarejestrowani
Postów: 217
Pomógł: 21
Dołączył: 10.06.2011
Skąd: Głogów

Ostrzeżenie: (0%)
-----


yy dane pobieram funkcjami str http://php.net/manual/en/ref.strings.php(te z początkiem str) albo preg_match
Kiedyś sprawdziłem ile pamięci zabierają klasy do dom'u, to płakać mi się chciało jakie to jest nie optymalne i przeciążające (SimpleHTMLDom), używanie tego jest dla mnie drogą na łatwizne kosztem optymalności skryptu.
Bardzo dużo pamięci je.
Co do szybkości, to nie testowałem, jedynie poprawiałem prace po "fachowcu".
Ale widze że nowy jesteś to ci dam gotowce które ci się przydadzą
  1. private function preciseBetweenstring($str,$first_start,$first_end,$second_start,$second_end,$mode = 1){
  2. list($first, $therest) = explode($first_end, stristr($str,$first_start));
  3. if($mode == 1){
  4. $str = $first;
  5. }
  6. elseif($mode ==2){
  7. $str = $therest;
  8. }
  9. $startsAt = strpos($str, $second_start) + strlen($second_start);
  10. $endsAt = strpos($str, $second_end, $startsAt);
  11. return substr($str, $startsAt, $endsAt - $startsAt);
  12. }
  13. private function getInbetweenStrings($start, $end, $str) {
  14. $matches = array();
  15. $regex = "/$start(.*?)$end/";
  16. preg_match_all($regex, $str, $matches);
  17. return $matches[1];
  18. }

+ jak chcesz betwen tylko jeden obiekt to
  1. $startsAt = strpos($str, $second_start) + strlen($second_start);
  2. $endsAt = strpos($str, $second_end, $startsAt);
  3. return substr($str, $startsAt, $endsAt - $startsAt);

skrypt moge napisać za 50zł, ale nie nauczysz się nic

Ten post edytował jackraymund 4.09.2013, 16:02:05


--------------------
Wykonuje zlecenia na pobieranie danych ze stron i różne boty.
Go to the top of the page
+Quote Post
kamykthm
post 5.09.2013, 02:47:51
Post #5





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 12.08.2009

Ostrzeżenie: (0%)
-----


Skrypt logowania:
  1. include ('simple_html_dom.php');
  2. function get_data($url, $post=null, $header=false, $cookie=null){
  3. $ch = curl_init($url);
  4. curl_setopt($ch, CURLOPT_POST, true);
  5. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7. if($header) curl_setopt($ch, CURLOPT_HEADER, true);
  8. if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  9. return curl_exec($ch);
  10. }
  11. //
  12. function add_postfields($data, &$post){
  13. $site = new DOMDocument();
  14. @$site->loadHTML($data);
  15. $inputs = $site->getElementsByTagName('input');
  16. foreach($inputs AS $input){
  17. if($input->hasAttribute('name')){
  18. switch($input->getAttributeNode('name')->value){
  19. case 'recaptcha_public_key':
  20. $post['recaptcha_public_key'] = $input->getAttributeNode('value')->value;
  21. break;
  22. case 'recaptcha_response_field':
  23. $post['recaptcha_response_field'] = $input->getAttributeNode('placeholder')->value;
  24. break;
  25. case 'http_referer':
  26. $post['http_referer'] = $input->getAttributeNode('value')->value;
  27. break;
  28. case 'form_key':
  29. $post['form_key'] = $input->getAttributeNode('value')->value;
  30. break;
  31. }
  32. }
  33. }
  34. }
  35. //
  36. function get_cookies($data){
  37. preg_match_all('|Set-Cookie: (.*);|U', $data, $matches);
  38. return implode('; ', $matches[1]);
  39. }
  40. //
  41. function tumblr($url, $email, $password){
  42. $post = array(
  43. 'user[email]' => $email,
  44. 'user[password]' => $password,
  45. 'user[age]' => 50,
  46. 'user[tos]' => 1
  47. );
  48. add_postfields(get_data('http://www.tumblr.com/login', http_build_query($post)), $post);
  49. $cookie = get_cookies(get_data('http://www.tumblr.com/login', http_build_query($post), true), $post);
  50. return get_data($url, null, false, $cookie);
  51. }
  52. $url = 'http://www.tumblr.com/new/blog';
  53. $email = 'a@b.pl';
  54. $password = '123';
  55. $data = tumblr($url, $email, $password);
  56. echo $data;


Ale mam problem, aby stworzyć nowy blog, do $url-a mi przechodzi, wypełniam pola jquery losową nazwą, ale jak daje submit, to wywala mi submita na mojej stronie... podpowie ktoś jak to obejść?

Ten post edytował kamykthm 5.09.2013, 02:48:39
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 07:36