Python 3.x 关于使用GET请求和Beautiful Soup进行web抓取的问题
我正在尝试使用Python 3.x 关于使用GET请求和Beautiful Soup进行web抓取的问题,python-3.x,web-scraping,beautifulsoup,Python 3.x,Web Scraping,Beautifulsoup,我正在尝试使用BeautifulSoup来获取URL 下面是我的代码: url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india' response = requests.get(url) s4 = BeautifulSoup(response.content, 'html.parser') s4 此外,我需要执行s4.title.text 这给了我一些奇怪的输出(似乎是用中文写的
BeautifulSoup
来获取URL
下面是我的代码:
url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india'
response = requests.get(url)
s4 = BeautifulSoup(response.content, 'html.parser')
s4
此外,我需要执行s4.title.text
这给了我一些奇怪的输出(似乎是用中文写的)
我试着手动打开URL,这似乎工作正常
我不知道如何解决这个问题。请建议
编辑#1:以下是输出的屏幕截图:
使用
s4=beautifulsop(response.text,'html.parser')
而不是s4=beautifulsop(response.content,'html.parser')
使用s4=beautifulsop(response.text,'html.parser')
你可以试试:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0 '}
url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india'
response = requests.get(url, headers=headers)
s4 = BeautifulSoup(response.text, 'lxml')
print(s4)
你可以试试:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0 '}
url= 'https://www.clinicspots.com/what-is-the-knee-replacement-surgery-cost-in-india'
response = requests.get(url, headers=headers)
s4 = BeautifulSoup(response.text, 'lxml')
print(s4)
它给了你什么?你得给我们看看!否则我们就不是翻译公司了。你的问题和编程语言有关吗?它给了你什么?你得给我们看看!否则我们就不是翻译公司了。您的问题与编程语言有关吗?