admin管理员组

文章数量:1313313

I have a script that uses the requests module to check a webpage for news updates. It worked up until a week ago, but now I am having a weird error. I am able to access the base url (www.example) using requests, but when I go to www.example/news/123456 it is appearing to have an error 500. This is what it says:

Internal Server Error
Sorry, There were some technical issues while processing your request.

However, I do not have this problem with selenium. Does anyone know what may be causing this error which is only happening with requests?

Here is my code:

import requests

url = 'www.example/news/123456/'
#Headers that I got from the (working) selenium request
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/90.0.4430.212 Safari/537.36'}
response = requests.get(url, headers=headers)

webpage_content = response.text
soup = BeautifulSoup(webpage_content, 'html.parser')
raw_lines = soup.find_all()

lines = '\n'.join([line.get_text() for line in raw_lines])
lines = lines.splitlines()

for line in lines:
    print(line)

本文标签: