英文:
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('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)
<!-- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论