所以我不知道我在使用Web抓取功能是什么,所以自然而然地我查找了教程,但是它们似乎都没有起作用。有人可以帮忙我的代码吗?
from selenium import webdriver
driver = webdriver.Chrome(executable_path='C:\Users\UserName\AppData\Local\Temp\Temp1_chromedriver_win32.zip\chromedriver.exe')
driver.get('http://toscrape.com/')
results = []
content = driver.page_source
soup = BeautifulSoup(content)
for element in soup.findAll(attrs='title'):
name = element.find('title')
results.append(name.text)
for x in results:
print(x)
答案 0 :(得分:0)
如果要打印汤的标题文本。
driver.get('http://toscrape.com/')
results = []
content = driver.page_source
soup = BeautifulSoup(content,"html.parser")
print(soup.title.text)
导入
from bs4 import BeautifulSoup
输出
抓取沙箱