python-3.x 使用post方法查找第二页

yebdmbv4  于 2023-06-25  发布在  Python
关注(0)|答案(1)|浏览(129)

我想用python程序下载一个m3u列表,但是我找不到结果页面,如果有人能帮我解决这个问题,我将不胜感激
网址=“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[password]='+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)
o2gm4chl

o2gm4chl1#

你解决这个问题的方法完全忽略了页面是通过JavaScript呈现的这一事实。您通过请求响应获得的是客户端返回的基本HTML,但JavaScript有效负载没有得到渲染,这就是为什么您看不到您正在查找的内容。
如果你想要一个纯Python的解决方案来解决这个问题,看看Selenium https://www.selenium.dev/documentation/webdriver/getting_started/,它是一个在浏览器中“模拟”真实的用户的框架,浏览器负责渲染元素。
然而,Selenium可能会变得棘手,因为它倾向于与基于Chromium的浏览器一起工作,它倾向于要求您维护代码并跟上版本更新,以确保跟上不断的Chrome版本更新。
我倾向于更喜欢基于JavaScript的解决方案,比如Puppeteer https://pptr.dev/,不需要太多的维护。

相关问题