python beautifulsoup findall在find中
我正在尝试获取td类“column-1”中的文本,我遇到了一些问题,因为它没有属性文本-但它显然有属性文本,所以我一定是做错了什么。代码如下:python beautifulsoup findall在find中,python,html,python-3.x,web-scraping,beautifulsoup,Python,Html,Python 3.x,Web Scraping,Beautifulsoup,我正在尝试获取td类“column-1”中的文本,我遇到了一些问题,因为它没有属性文本-但它显然有属性文本,所以我一定是做错了什么。代码如下: import urllib import urllib.request from bs4 import BeautifulSoup theurl="http://vermontamerican.com/products/standard-drill-bit-extensions/" thepage = urllib.request.urlopen(th
import urllib
import urllib.request
from bs4 import BeautifulSoup
theurl="http://vermontamerican.com/products/standard-drill-bit-extensions/"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage,"html.parser")
for part in soup.find_all('td'),{"class":"column-1"}:
part1 = part.text
print(part1)
如果我把第2行去掉,只打印上面的“部分”,我会得到一个结果,但它给出的是所有td,而不仅仅是第1列。
我也试过,但我是新来的,所以我确信这在很多方面都是错误的
import urllib
import urllib.request
from bs4 import BeautifulSoup
theurl="http://vermontamerican.com/products/standard-drill-bit-extensions/"
thepage = urllib.request.urlopen(theurl)
soup = BeautifulSoup(thepage,"html.parser")
for part in soup.find('tbody'),{"class":"row-hover"}:
for part1 in part.find_all('a'):
print(part1)
您没有将属性选择字典传递到
find\u all()
函数中。替换:
for part in soup.find_all('td'),{"class":"column-1"}:
与:
现在,您的代码将生成:
17103
17104
17103
17104