如何找到正确的答案;分区;使用python进行web抓取
我似乎无法“检查”漂亮汤的正确功能。我试图遵循这些指南,但我似乎无法超越这一点 我试图通过一个网站来比较四款汽车的安全性能、维护成本和价格。我正在使用spyder(python 3.6)如何找到正确的答案;分区;使用python进行web抓取,python,html,Python,Html,我似乎无法“检查”漂亮汤的正确功能。我试图遵循这些指南,但我似乎无法超越这一点 我试图通过一个网站来比较四款汽车的安全性能、维护成本和价格。我正在使用spyder(python 3.6) 我知道我必须做一些改变,但现在我只希望它运行时不会出错 运行文件('C:/Users/st.s.mahathirath.ctr/.spyder-py3/temp.py',wdir='C:/Users/st.s.mahathirath.ctr/.spyder-py3') 回溯(最近一次呼叫最后一次): 文
我知道我必须做一些改变,但现在我只希望它运行时不会出错
运行文件('C:/Users/st.s.mahathirath.ctr/.spyder-py3/temp.py',wdir='C:/Users/st.s.mahathirath.ctr/.spyder-py3') 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 运行文件('C:/Users/st.s.mahathirath.ctr/.spyder-py3/temp.py',wdir='C:/Users/st.s.mahathirath.ctr/.spyder-py3') 文件“C:\ProgramData\Anaconda3\lib\site packages\spyder\utils\site\site customize.py”,第705行,在runfile中 execfile(文件名、命名空间) 文件“C:\ProgramData\Anaconda3\lib\site packages\spyder\utils\site\sitecustomize.py”,第102行,在execfile中 exec(编译(f.read(),文件名,'exec'),命名空间) 文件“C:/Users/st.s.mahathirath.ctr/.spyder-py3/temp.py”,第2行,在 从urllib导入urlopen作为uReq ImportError:无法导入名称“urlopen”
from urllib.request urlopen as uReq
我觉得这像是打字错误?也许你的意思是:
从urllib.request导入urlopen作为uReq
请尝试以下代码:
import bs4
from urllib import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.caranddriver.com/car-comparison-tool?chromeIDs=404121,402727,403989,403148'
# opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
# html parsing
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("div", {
"class": "w50p "
})
我想你是想拿汽车比较,我想这可能行不通,因为
- 这在命令行中不起作用,因为站点将抛出不受支持的浏览器李>
- 在比较了现场的汽车(太多)后,div不是要寻找的元素。尝试调试器控制台中的
查看4项(其中最后一项是“添加汽车”项)。在这张cd-view汽车卡中,有一个单独的div和两个孩子,第二个孩子(div)包含所有相关信息(根据当前的网站设计)document.getElementsByTagName('cd-view-car-card')
希望这能有所帮助它仍然给了我一个语法错误:无效语法我们需要更多的信息才能从中得到有用的东西。还有,你自己试过什么?
import bs4
from urllib import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.caranddriver.com/car-comparison-tool?chromeIDs=404121,402727,403989,403148'
# opening up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
# html parsing
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("div", {
"class": "w50p "
})