使用POST方法查找第二页。

huangapple go评论137阅读模式
英文:

Find second page with post method

问题

我想使用Python程序下载一个m3u列表,但是我无法找到使用POST方法的结果页面,如果有人能帮助我解决这个问题,我将不胜感激。

URL= "https://playtvnow.com/shop1/order/trial-products/1"

from __future__ import print_function
import requests, json, re, random, string, time, warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter('ignore', InsecureRequestWarning)
post_url='https://playtvnow.com/shop1/modules/addons/LagomOrderForm/api/index.php/cart/registration-type/update'
post_url2='https://playtvnow.com/shop1/modules/addons/LagomOrderForm/api/index.php/cart/billing-details/update'

def get_clipmails():
    Headers_={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0',
              'Accept': 'application/json, text/plain, */*',
              'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
              'Content-Type': 'application/x-www-form-urlencoded',
              'Origin': 'https://playtvnow.com/',
              'Connection': 'keep-alive',
              'Referer': 'https://playtvnow.com/shop1/order/trial-products/1',
              'Accept-Encoding':'gzip'}#, deflate, br'}
    params='details[firstname]='+NAME_TARGET+'&details[lastname]='+LAST_TARGET+'&details[email]='+EMAIL_TARGET+'&details[callingCode]=1&details[phonenumber]='+PHON_TARGET+'&details[companyname]=&details[tax_id]=&details[address1]='+ADRS_TARGET+'&details[address2]='+ADRS_TARGET+'&details[city]='+CITY_TARGET+'&details[state]='+STATE_TARGET+'&details[country]=US&details
		
输入密码查看隐藏内容

='
+RND_PASS+'&details[password2]='+RND_PASS+'&details[postcode]='+ZIP_TARGET+'&paymentMethod=mailin&details[marketingoptin]=1&details[country-calling-code-phonenumber]=1&acceptTos=&currency=1&'
post_data2=requests.post(post_url2, headers=Headers_, data=params).text print("POST DATA2:", post_data2) post_data=requests.post(post_url, headers=Headers_, data=params).text print("POST DATA:", post_data)
英文:

I want to download a m3u list with a python program but I can't find the results page with the post method if someone can help me solve the problem I would be grateful

URL= "https://playtvnow.com/shop1/order/trial-products/1"

<!-- begin snippet: js hide: false console: true babel: true -->

<!-- language: lang-css -->

from __future__ import print_function
import requests , json, re,random,string,time,warnings
from requests.packages.urllib3.exceptions import InsecureRequestWarning
warnings.simplefilter(&#39;ignore&#39;,InsecureRequestWarning)
post_url=&#39;https://playtvnow.com/shop1/modules/addons/LagomOrderForm/api/index.php/cart/registration-type/update&#39;
post_url2=&#39;https://playtvnow.com/shop1/modules/addons/LagomOrderForm/api/index.php/cart/billing-details/update&#39;

                                                                                                                                                                                                                                                                                                 
def get_clipmails():     
    Headers_={&#39;User-Agent&#39;: &#39;Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0&#39;,
              &#39;Accept&#39;: &#39;application/json, text/plain, */*&#39;,
              &#39;Accept-Language&#39;: &#39;fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3&#39;,
              &#39;Content-Type&#39;:&#39;application/x-www-form-urlencoded&#39;,
              &#39;Origin&#39;: &#39;https://playtvnow.com/&#39;,
              &#39;Connection&#39;: &#39;keep-alive&#39;,
              &#39;Referer&#39;: &#39;https://playtvnow.com/shop1/order/trial-products/1&#39;,
              &#39;Accept-Encoding&#39;:&#39;gzip&#39;}#, deflate, br&#39;}
    params=&#39;details[firstname]=&#39;+NAME_TARGET+&#39;&amp;details[lastname]=&#39;+LAST_TARGET+&#39;&amp;details[email]=&#39;+EMAIL_TARGET+&#39;&amp;details[callingCode]=1&amp;details[phonenumber]=&#39;+PHON_TARGET+&#39;&amp;details[companyname]=&amp;details[tax_id]=&amp;details[address1]=&#39;+ADRS_TARGET+&#39;&amp;details[address2]=&#39;+ADRS_TARGET+&#39;&amp;details[city]=&#39;+CITY_TARGET+&#39;&amp;details[state]=&#39;+STATE_TARGET+&#39;&amp;details[country]=US&amp;details
		
输入密码查看隐藏内容

=&#39;+RND_PASS+&#39;&amp;details[password2]=&#39;+RND_PASS+&#39;&amp;details[postcode]=&#39;+ZIP_TARGET+&#39;&amp;paymentMethod=mailin&amp;details[marketingoptin]=1&amp;details[country-calling-code-phonenumber]=1&amp;acceptTos=&amp;currency=1&amp;&#39; post_data2=requests.post(post_url2,headers=Headers_,data=params).text print(&quot;POST DATA2:&quot;,post_data2) post_data=requests.post(post_url,headers=Headers_,data=params).text print(&quot;POST DATA:&quot;,post_data)

<!-- end snippet -->

答案1

得分: 1

你解决这个问题的方法完全忽略了页面是通过Javascript渲染的这一事实。通过请求响应获得的只是客户端返回的裸HTML,但Javascript负载不会被渲染,这就是为什么你看不到你正在寻找的内容的原因。

如果你想要一个纯粹的Python解决方案,可以看看Selenium,它是一个模拟浏览器中的真实用户的框架,浏览器负责渲染元素。

然而,Selenium可能会变得棘手,因为它通常与基于Chromium的浏览器一起使用,所以需要维护代码并跟踪版本更新,以确保与不断更新的Chrome版本保持同步。

我更倾向于像Puppeteer这样的基于Javascript的解决方案,它不需要太多的维护。

英文:

Your approach to the problem is completely missing the fact that the page gets rendered via Javascript. What you get through the request response, is the bare-bone HTML returned by the client, but the Javascript payload doesn't get rendered, and that's why you can't see the content you're looking for.

If you want a purely python solution to this problem, look at Selenium https://www.selenium.dev/documentation/webdriver/getting_started/ , which is a framework that 'simulates' a real user in a browser, where the browser takes care of rendering elements.

However, Selenium can get tricky, and since it tends to work with Chromium based browser, it tends to require that you maintain your code and keep up with version updates to make sure to keep up with constant Chrome version update.

I tend to prefer Javascript based solutions like Puppeteer https://pptr.dev/ that don't require so much upkeep.

huangapple
  • 本文由 发表于 2023年6月16日 13:28:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76487186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定