简体   繁体   English

在美丽的汤中循环/没有错误

[英]looping in beautiful soup / no errors

I have been writing a program that would hypothetically find items on a website as soon as they were loaded onto the website.我一直在编写一个程序,它会在加载到网站后立即在网站上查找项目。 As of now the script takes as input, two different values (keywords) used to describe an item and a color used to pick the color of the item.截至目前,脚本将用于描述项目的两个不同值(关键字)和用于选择项目颜色的颜色作为输入。 The parsing is spot on with items that are already on the website but lets say that I run my program before the website loads the items, instead of having to re run the entire script i'd like for it to just refresh the page and re-parse the data until it found it.解析是在网站上已经存在的项目上进行的,但可以说我在网站加载项目之前运行我的程序,而不必重新运行整个脚本,我希望它只是刷新页面并重新- 解析数据直到找到它。 I also included no errors in my question because from my example run of the script I entered Keywords and Color not pertaining to item on the website and instead of getting an error, I just got " Process finished with exit code 0".我的问题中也没有包含任何错误,因为从我的脚本示例运行中,我输入了与网站上的项目无关的关键字和颜色,而不是出现错误,我只是得到“进程已完成,退出代码为 0”。 Thank you in advance to any who take the time to help !在此先感谢任何花时间提供帮助的人!

Here is my code:这是我的代码: 在此处输入图片说明

As another user suggested, you're probably better off using Selenium for the entire process rather than using it for only parts of your code and swapping between BSoup and Selenium.正如另一位用户所建议的那样,您最好在整个过程中使用 Selenium,而不是仅将其用于部分代码并在 BSoup 和 Selenium 之间进行交换。

As for reloading the page if certain items are not present, if you already know which items are supposed to be on the page then you can simply search for each item by id with selenium and if you can't find one or more then refresh the page with the following line of code:至于在某些项目不存在的情况下重新加载页面,如果您已经知道页面上应该有哪些项目,那么您可以使用 selenium 通过 id 搜索每个项目,如果找不到一个或多个,则刷新具有以下代码行的页面:

driver.refresh()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM