为什么我不能使用python请求来请求某个网页

2024-09-26 18:10:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我进不了this webpage。 当我尝试使用requests.get(url)时,它根本没有进展,我没有得到任何HTTP错误,只是挂起,就像它在反复尝试一样。你知道吗

我试过使用session和header,但都不适合我。你知道吗

import bs4
from bs4 import BeautifulSoup as bs
import requests


url="https://www.gogoanime1.com/watch/hangyakusei-million-arthur-2nd-season/episode/episode-1"
epn=int(input("enter which episode link is it?: "))
newses=requests.Session()
newses.headers.update({'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'})
ssn=newses.get(url)
page=ssn.text
print()

soup=bs(page,'html.parser')
a=soup.find('div',{'class':'vmn-buttons'})
links=a.find_all('a')

for link in links:
    print(link)
    if link.text=="Download":
        print("found")
        dl=link['href']
        break
print(dl)

bom=newses.get(dl)
print(bom.text)

我想至少有一个回应,但它整天挂在那里,我怎么能像一个真正的用户访问网页,刮它的内容?你知道吗


Tags: textimporturlgetbspagelinkrequests

热门问题