Информация об изменениях

Сообщение Re: Как распарсить https://apnews.com/ от 05.11.2024 22:20

Изменено 05.11.2024 22:42 kov_serg

Re: Как распарсить https://apnews.com/
Здравствуйте, Passerby, Вы писали:

P>Посмотрел консоль браузера, Network и не нашел никаких запросов. Все скрыто или не так делаю?


1. выкинте C# и используйте python или php или что-то другое скриптовое и не типизированное

<?php require "simple_html_dom.php"; // https://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/1.9.1

$url='https://apnews.com/politics';

$ctx=stream_context_create(['http'=>[
    'method'=>"GET",
    'header'=>"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0\r\n" .
              "Cookie: cf_clearance=3s8Cea18hD986ddrDiZf._DZ6B1iSLSGGEdzXPkEp1Q-1730843870-1.2.1.1-WHtjEk_hkWNncf7cNcHVOp34HitcyxkXeAvA2Bn_4SU3ZhWWo33kTp0Q0KGabjWhWBpCiZKoZNBAVT8ounNQyHdKuOt5Az9dZkJcBl.tT24Jk4GBhSi_pNuf29X83KazgVncJMlD4NRXwdpFIDV6fxsgNOmXL12Pqv3BbMUEeCPDXGG6dQDBzTelwRHyqOm1024boPi2Tv2jqLa.2Bsr6WHQLLvMPFrPf2qD5l2pOJ_ZD7wowanSDVZI57JDDhnY.SEGFvekz7H3YlKPlkEii.uRHQ12Zin0uKSyItslFULbVRJb4CIRFNIks._qBSEf.m6rLaKqXy8G9gVjDRSQNl3IfH55Roh0wRXsD5YJk6qMDmSBu77aA48D4I1B.lm6\r\n"
]]);

$html=file_get_html($url,false,$ctx);

$i=0;foreach($html->find('.PagePromo-title') as $title) {
    $news_text=trim($title->plaintext);
    $news_url='';$link=$title->find('a',0); if ($link) $news_url=$link->href;
    //printf("%2d. <a href='%s'>%s</a><br/>\n",++$i,$news_url,htmlspecialchars($news_text));
    printf("%2d. %s\n",++$i,$news_text);
}

  output
 1. A sharply divided America decides between Trump and Harris
 2. Control of Congress is at stake and with it a president’s agenda
 3. Economy ranked as a top issue, but concerns over democracy drove many voters to polls
 4. Trump snaps at reporter when asked about abortion: ‘Stop talking about that’
 5. Abortion is on the ballot in nine states and motivating voters across the US
 6. Election 2024 LIVE: AP coverage and latest news on the presidential election
 7. Harris and Trump tie in first election result in Dixville Notch
 8. Trump says Republicans showing up at polls in force
 9. Here’s what to watch on Election Day in the US
10. Congressional election updates: Senate and House control could be decided by handful of races
11. Voting period marked by massive early turnout ends with few problems, generally smooth Election Day
12. See when polls close in battleground states
13. On the night before Election Day, Kamala Harris brings in celebrities. Donald Trump is unimpressed
14. Trump called Megyn Kelly ‘nasty’ 9 years ago. She just helped deliver his closing message
15. Bernie Sanders seeks a fourth Senate term representing Vermont
16. A presidential campaign unlike any other ends on Tuesday. Here’s how we got here
17. Biden suggests he’d like to smack ‘macho guys’ during final campaign stop
18. Biden declares major disaster area in southeast New Mexico due to historic flooding
19. Cyprus is committed to expanding defense ties with the US, says its president
20. Venezuela’s rejection from developing economies alliance heightens tensions with member Brazil
21. What it’s like in a ‘chaos’ Congress and why these lawmakers keep coming back
22. Jim Jordan failed to become speaker last year. But his rise in the GOP may not be over yet
23. Supreme Court will weigh in on new mostly Black Louisiana congressional district, after election
24. Supreme Court’s conservative justices leave in place Virginia’s purge of voter registrations
25. Virginia asks US Supreme Court to reinstate removals of 1,600 voter registrations
26. A Supreme Court reshaped by Trump has a low profile in this presidential campaign
27. Empty seats become a more common sight at Trump’s final rallies
28. Harris campaign spends final hours reminding Pennsylvania of a Trump ally’s joke about Puerto Rico
29. ‘Fat Leonard,’ Navy contractor behind one of the military’s biggest scandals, sentenced to 15 years
30. Democratic-backed justices look to defend control of Michigan’s Supreme Court
31. Central Michigan voters are deciding 2 open congressional seats in the fight for the US House
32. Beyoncé channels Pamela Anderson in ‘Baywatch’ for Halloween video asking viewers to vote
33. Home Depot’s co-founder and billionaire philanthropist dies at 95
34. Rudy Giuliani ordered to appear in court after missing deadline to turn over Mercedes, other assets
35. Election Day voting underway as Americans chose between Harris or Trump
36. Ground Game: America arrives at Election Day with control of Congress at stake
37. North Dakota measures would end local property taxes and legalize recreational marijuana
38. GOP senator from North Dakota faces Democratic challenger making her 2nd US Senate bid
39. North Dakota’s lone congressman seeks to continue GOP’s decades-old grip on the governor’s post
40. South Dakota is deciding whether to protect abortion rights and legalize recreational marijuana
41. Democratic Rep. Angie Craig seeks a 4th term in Minnesota’s tightest congressional race
42. Democratic Sen. Amy Klobuchar is a heavy favorite to win 4th term against ex-NBA player Royce White
43. Democrats defend Michigan’s open Senate seat, a rare opportunity for Republicans
44. Alaska voters deciding a hard-fought race for the state’s only US House seat, election issues
45. West Virginians’ governor choices stand on opposite sides of the abortion debate
46. A former Trump aide and a longtime congressman are likely to win in high-profile Georgia races
47. GOP Gov. Jim Justice battles Democrat Glenn Elliott for US Senate seat from West Virginia
48. Georgia Democratic prosecutor pursuing election case against Trump faces Republican challenger
49. Voters in battleground Arizona to decide if local agencies can police illegal immigration
50. US Rep. John Curtis is favored to win Mitt Romney’s open Senate seat in Utah
51. Utah Gov. Spencer Cox is expected to win reelection after his surprising endorsement of Trump
52. Democrat Ruben Gallego faces Republican Kari Lake in US Senate race in Arizona
53. Democrats hope to keep winning streak alive in Washington governor’s race
54. GOP tries to break Connecticut Democrats’ winning streak in US House races
55. Landmark Washington climate law faces possible repeal by voters
56. First-term Democrat tries to hold on in Washington state district won by Trump in 2020
57. Justices who split on an abortion measure ruling vie to lead Arkansas Supreme Court
58. Connecticut to decide on constitution change to make mail-in voting easier

ps: как получать cf_clearance надеюсь не надо расcказывать
Re: Как распарсить https://apnews.com/
Здравствуйте, Passerby, Вы писали:

P>Посмотрел консоль браузера, Network и не нашел никаких запросов. Все скрыто или не так делаю?


1. выкинте C# и используйте python или php или что-то другое скриптовое и не типизированное

<?php require "simple_html_dom.php"; // https://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/1.9.1

$url='https://apnews.com/politics';

$ctx=stream_context_create(['http'=>[
    'method'=>"GET",
    'header'=>"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0\r\n" .
              "Cookie: cf_clearance=3s8Cea18hD986ddrDiZf._DZ6B1iSLSGGEdzXPkEp1Q-1730843870-1.2.1.1-WHtjEk_hkWNncf7cNcHVOp34HitcyxkXeAvA2Bn_4SU3ZhWWo33kTp0Q0KGabjWhWBpCiZKoZNBAVT8ounNQyHdKuOt5Az9dZkJcBl.tT24Jk4GBhSi_pNuf29X83KazgVncJMlD4NRXwdpFIDV6fxsgNOmXL12Pqv3BbMUEeCPDXGG6dQDBzTelwRHyqOm1024boPi2Tv2jqLa.2Bsr6WHQLLvMPFrPf2qD5l2pOJ_ZD7wowanSDVZI57JDDhnY.SEGFvekz7H3YlKPlkEii.uRHQ12Zin0uKSyItslFULbVRJb4CIRFNIks._qBSEf.m6rLaKqXy8G9gVjDRSQNl3IfH55Roh0wRXsD5YJk6qMDmSBu77aA48D4I1B.lm6\r\n"
]]);

$html=file_get_html($url,false,$ctx);

$i=0;foreach($html->find('.PagePromo-title') as $title) {
    $news_text=trim($title->plaintext);
    $news_url='';$link=$title->find('a',0); if ($link) $news_url=$link->href;
    //printf("%2d. <a href='%s'>%s</a><br/>\n",++$i,$news_url,htmlspecialchars($news_text));
    printf("%2d. %s\n",++$i,$news_text);
}

  output
 1. A sharply divided America decides between Trump and Harris
 2. Control of Congress is at stake and with it a president’s agenda
 3. Economy ranked as a top issue, but concerns over democracy drove many voters to polls
 4. Trump snaps at reporter when asked about abortion: ‘Stop talking about that’
 5. Abortion is on the ballot in nine states and motivating voters across the US
 6. Election 2024 LIVE: AP coverage and latest news on the presidential election
 7. Harris and Trump tie in first election result in Dixville Notch
 8. Trump says Republicans showing up at polls in force
 9. Here’s what to watch on Election Day in the US
10. Congressional election updates: Senate and House control could be decided by handful of races
11. Voting period marked by massive early turnout ends with few problems, generally smooth Election Day
12. See when polls close in battleground states
13. On the night before Election Day, Kamala Harris brings in celebrities. Donald Trump is unimpressed
14. Trump called Megyn Kelly ‘nasty’ 9 years ago. She just helped deliver his closing message
15. Bernie Sanders seeks a fourth Senate term representing Vermont
16. A presidential campaign unlike any other ends on Tuesday. Here’s how we got here
17. Biden suggests he’d like to smack ‘macho guys’ during final campaign stop
18. Biden declares major disaster area in southeast New Mexico due to historic flooding
19. Cyprus is committed to expanding defense ties with the US, says its president
20. Venezuela’s rejection from developing economies alliance heightens tensions with member Brazil
21. What it’s like in a ‘chaos’ Congress and why these lawmakers keep coming back
22. Jim Jordan failed to become speaker last year. But his rise in the GOP may not be over yet
23. Supreme Court will weigh in on new mostly Black Louisiana congressional district, after election
24. Supreme Court’s conservative justices leave in place Virginia’s purge of voter registrations
25. Virginia asks US Supreme Court to reinstate removals of 1,600 voter registrations
26. A Supreme Court reshaped by Trump has a low profile in this presidential campaign
27. Empty seats become a more common sight at Trump’s final rallies
28. Harris campaign spends final hours reminding Pennsylvania of a Trump ally’s joke about Puerto Rico
29. ‘Fat Leonard,’ Navy contractor behind one of the military’s biggest scandals, sentenced to 15 years
30. Democratic-backed justices look to defend control of Michigan’s Supreme Court
31. Central Michigan voters are deciding 2 open congressional seats in the fight for the US House
32. Beyoncé channels Pamela Anderson in ‘Baywatch’ for Halloween video asking viewers to vote
33. Home Depot’s co-founder and billionaire philanthropist dies at 95
34. Rudy Giuliani ordered to appear in court after missing deadline to turn over Mercedes, other assets
35. Election Day voting underway as Americans chose between Harris or Trump
36. Ground Game: America arrives at Election Day with control of Congress at stake
37. North Dakota measures would end local property taxes and legalize recreational marijuana
38. GOP senator from North Dakota faces Democratic challenger making her 2nd US Senate bid
39. North Dakota’s lone congressman seeks to continue GOP’s decades-old grip on the governor’s post
40. South Dakota is deciding whether to protect abortion rights and legalize recreational marijuana
41. Democratic Rep. Angie Craig seeks a 4th term in Minnesota’s tightest congressional race
42. Democratic Sen. Amy Klobuchar is a heavy favorite to win 4th term against ex-NBA player Royce White
43. Democrats defend Michigan’s open Senate seat, a rare opportunity for Republicans
44. Alaska voters deciding a hard-fought race for the state’s only US House seat, election issues
45. West Virginians’ governor choices stand on opposite sides of the abortion debate
46. A former Trump aide and a longtime congressman are likely to win in high-profile Georgia races
47. GOP Gov. Jim Justice battles Democrat Glenn Elliott for US Senate seat from West Virginia
48. Georgia Democratic prosecutor pursuing election case against Trump faces Republican challenger
49. Voters in battleground Arizona to decide if local agencies can police illegal immigration
50. US Rep. John Curtis is favored to win Mitt Romney’s open Senate seat in Utah
51. Utah Gov. Spencer Cox is expected to win reelection after his surprising endorsement of Trump
52. Democrat Ruben Gallego faces Republican Kari Lake in US Senate race in Arizona
53. Democrats hope to keep winning streak alive in Washington governor’s race
54. GOP tries to break Connecticut Democrats’ winning streak in US House races
55. Landmark Washington climate law faces possible repeal by voters
56. First-term Democrat tries to hold on in Washington state district won by Trump in 2020
57. Justices who split on an abortion measure ruling vie to lead Arkansas Supreme Court
58. Connecticut to decide on constitution change to make mail-in voting easier

ps: как получать cf_clearance надеюсь не надо расcказывать