Python 使用bs4翻译页面后,将其刮平

Python 使用bs4翻译页面后,将其刮平,python,web-scraping,beautifulsoup,http-accept-language,Python,Web Scraping,Beautifulsoup,Http Accept Language,我正试图通过把一页在法国的内容翻译成英语来刮去它 下面是我在python中使用漂亮的soup和requests包的代码 import requests from bs4 import BeautifulSoup url = '<url>' headers = {"Accept-Language": "en,en-gb;q=0.5"} r = requests.get(url, headers=headers) c = r.content soup = BeautifulSoup(c)

我正试图通过把一页在法国的内容翻译成英语来刮去它

下面是我在python中使用漂亮的soup和requests包的代码

import requests
from bs4 import BeautifulSoup
url = '<url>'
headers = {"Accept-Language": "en,en-gb;q=0.5"}
r = requests.get(url, headers=headers)
c = r.content
soup = BeautifulSoup(c)
导入请求
从bs4导入BeautifulSoup
url=“”
headers={“接受语言”:“en,en gb;q=0.5”}
r=requests.get(url,headers=headers)
c=r.content
汤=美汤(c)
但这仍然是法语文本

任何人都可以建议更改/替代代码。

您可以利用将字符串转换为各种语言,例如从法国易趣网站转换跨度:

import requests
from bs4 import BeautifulSoup
from textblob import TextBlob

url = 'https://www.ebay.fr/'
french = []
english = []
r = requests.get(url)
c = r.content
soup = BeautifulSoup(c)
for li in soup.find_all('span'):
    french.append(li.text)

Frenchstr = ''.join(french)
blob = TextBlob(Frenchstr)
print(Frenchstr)
Englishstr = blob.translate(to="EN")
print('------------------------------------------------')
print(Englishstr)

谢谢,我会在废弃的数据上试用。