Python 有没有办法翻译网页语言,或者在使用scrapy进行抓取的同时翻译抓取的数据?
我打算用英语语言搜索dintex.net网站,但找不到任何方法将搜索到的数据转换成英语。我也用过谷歌,但它也显示了错误,所以有没有其他方法将该页面或数据转换为英语Python 有没有办法翻译网页语言,或者在使用scrapy进行抓取的同时翻译抓取的数据?,python,web,web-scraping,scrapy,Python,Web,Web Scraping,Scrapy,我打算用英语语言搜索dintex.net网站,但找不到任何方法将搜索到的数据转换成英语。我也用过谷歌,但它也显示了错误,所以有没有其他方法将该页面或数据转换为英语 import scrapy from googletrans import Translator class DtSpider(scrapy.Spider): name = 'dt' start_urls = ['http://www.dintex.net'] def parse(self, response): urls
import scrapy
from googletrans import Translator
class DtSpider(scrapy.Spider):
name = 'dt'
start_urls = ['http://www.dintex.net']
def parse(self, response):
urls = response.xpath('//*[@class="listing-btn btn btn-primary btn-block w-100"]/@href').extract()
for url in urls:
url = response.urljoin(url)
yield scrapy.Request(url=url, callback=self.parse_details)
np = response.xpath('//*[@class="page-item"]/a[@rel="next"]/@href').extract_first()
ap = response.urljoin(np)
yield scrapy.Request(url=ap,callback=self.parse)
def parse_details(self,response):
Title = response.xpath('//*[@class="show-info__title"]/text()').extract_first()
Location = response.xpath('//*[@class="show-info__location"]/p/text()').extract_first()
Contact = response.xpath('//*[@class="show-info__contact-details__phone-link"]/text()').extract_first()
Contact = Contact.replace('Whatsapp ','')
Description = response.xpath('//*[@class="show-info__section-text"]/p/text()').extract_first()
Manufacture = response.xpath('//td[contains(text(),"Fabricante")]/following-sibling::td/text()').extract_first()
Model = response.xpath('//td[contains(text(),"Modelo")]/following-sibling::td/text()').extract_first()
Year = response.xpath('//td[contains(text(),"Año")]/following-sibling::td/text()').extract_first()
Condition = response.xpath('//td[contains(text(),"Condición")]/following-sibling::td/text()').extract_first()
img = response.xpath('//*[@class="gallery__item"]/img/@src').extract_first()
thumbs = response.xpath('//img/@lazy-src').extract()
#t = Translator()
#Title = t.translate(Title).text
#Location = t.translate(Location).text
#Contact = t.translate(Contact).text
#Description = t.translate(Description).text
#Manufacture = t.translate(Manufacture).text
#Model = t.translate(Model).text
#Year = t.translate(Year).text
#Condition = t.translate(Condition).text
yield{'Title': Title,
'Location' : Location,
'Contact' : Contact,
'Description' : Description,
'Manufacture' : Manufacture,
'Model' : Model,
'Year' : Year,
'Condition' : Condition,
'Img' : img,
'Thums' : thumbs
}
我想你应该把这个饼干和你的要求一起寄出去
googtrans=/es/en
因为页面允许根据可用语言/区域的选择进行本地化
你需要这样做
请参阅中的cookie部分
您正在生成的请求可能需要更改如下内容(未测试)
我想你应该把这个饼干和你的要求一起寄出去
googtrans=/es/en
因为页面允许根据可用语言/区域的选择进行本地化
你需要这样做
请参阅中的cookie部分
您正在生成的请求可能需要更改如下内容(未测试)