我对Python还比较陌生,我正在构建一个小应用程序,将西班牙语论坛中的一个特定单词废弃,这样我就可以尝试获取有关任天堂Switch股票(很难获得)以及培训/娱乐的新闻。我打算每隔15分钟左右检查一次,然后将更新发送到Telegrambot,但目前我正努力从整个线程中获取结果。你知道吗
下面是一个示例:
import requests
#TODO: Have the get method loop through every iteration of a forum page: s10, s20, s30...
from bs4 import BeautifulSoup
url = "https://www.elotrolado.net/hilo_disponibilidad-nintendo-switch-seguimiento-de-pedidos_2210603_s"
for i in range(10,10000,10):
stringer = str(i)
page = requests.get(url%(stringer,)).read()
soup = BeautifulSoup(page.content, "lxml")
results = soup.find_all(lambda tag: "stock" in tag.string if tag.string else False)
scraped_paragraphs = map(lambda element: element.string, results)
print(scraped_paragraphs)
当我运行这个时,我得到TypeError: not all arguments converted during string formatting
论坛的每个新页面都会在URL的末尾添加10个,如下所示:
First page: https://www.elotrolado.net/hilo_disponibilidad-nintendo-switch-seguimiento-de-pedidos_2210603
Second page: https://www.elotrolado.net/hilo_disponibilidad-nintendo-switch-seguimiento-de-pedidos_2210603_s10
Third page: https://www.elotrolado.net/hilo_disponibilidad-nintendo-switch-seguimiento-de-pedidos_2210603_s20
etc...
不知道我在这里遗漏了什么,我已经设法废弃了一个页面,但这个循环正在抵制我!你知道吗
我不确定您的预期输出是什么,但请尝试以下操作:
for i in range(10, 10000, 10): stringer = int(i) page = requests.get(url + '%d' % stringer) print(page) soup = BeautifulSoup(page.content, "lxml") results = soup.find_all(lambda tag: "stock" in tag.string if tag.string else False) scraped_paragraphs = list(map(lambda element: element.string, results)) print(scraped_paragraphs)
我想试着寻找一个字符串,我知道它存在于这个系列的一个页面中:“amazon”。我看到代码中有两个可能的小缺陷。你知道吗
一个是它无法识别case中的变体(例如“Amazon”、“Amazon”等)。另一个是
map
产生一个迭代器。你知道吗相关问题 更多 >
编程相关推荐