我正在尝试从不同站点获取有关某些产品的信息。这是我的程序的结构:
product_list = [iPad, iPhone, AirPods, ...]
def spider_tmall:
self.driver.find_element_by_id('searchKeywords').send_keys(inputlist[a])
# ...
def spider_jd:
self.driver.find_element_by_id('searchKeywords').send_keys(inputlist[a])
# ...
if __name__ == '__main__':
for a in range(len(inputlist)):
process = CrawlerProcess(settings={
"FEEDS": {
"itemtmall.csv": {"format": "csv",
'fields': ['product_name_tmall', 'product_price_tmall', 'product_discount_tmall'], },
"itemjd.csv": {"format": "csv",
'fields': ['product_name_jd', 'product_price_jd', 'product_discount_jd'], },
})
process.crawl(tmallSpider)
process.crawl(jdSpider)
process.start()
Run Code Online (Sandbox Code Playgroud)
基本上,我想为product_list. 现在,我的程序只运行一次所有蜘蛛(在这种情况下,它为 iPad 完成工作)然后出现ReactorNotRestartable错误并且程序终止。有谁知道如何修复它?此外,我的总体目标是多次运行蜘蛛,输入不一定是列表。它可以是 CSV 文件或其他文件。任何建议将不胜感激!
我想模拟汉字的 URL 编码。对于我的用例,我有一个电子商务网站的搜索 URL
'https://search.jd.com/Search?keyword={}'.format('ipad')
Run Code Online (Sandbox Code Playgroud)
当我用英语搜索产品时,这很好用。但是,我需要输入中文,我试过了
'https://search.jd.com/Search?keyword={}'.format('??t?')
Run Code Online (Sandbox Code Playgroud)
,并在网络选项卡下找到以下编码
https://list.tmall.com/search_product.htm?q=%C4%CD%BF%CBt%D0%F4
Run Code Online (Sandbox Code Playgroud)
所以基本上,我需要编码输入,如 '??t?' 进入'%C4%CD%BF%CBt%D0%F4'。我不确定网站使用的是哪种编码?另外,如何使用python将汉字转换为这些编码?
更新:我检查了标题,内容编码似乎是 gzip?