他们已经成功了,但现在我想从文本中收集数据;而不是标题。等:
“小米70Mai Pro”
我试着引用这两个来源;但我还是不确定。。。
-
WebScraper-Sample
-
Parse HTML Table for URL, Place into List
links = 'SampleLink... with table cell'
def getURLData(url): # scrap data from Link
try:
page = requests.get(url)
content = page.content
soup = BeautifulSoup(content, "html.parser")
return soup
except Exception as e:
print('Error.getURLData:', e)
return None
inputLink = getURLData(links)
def tableCheck(): # if there's a table cell;
data = []
for table_tag in inputLink.find_all('td', {'class': 'row1'}):
topic_title = table_tag.find('a', href=True)
if topic_title:
datum = {'topic_title': topic_title['title']}
data.append(datum)
return data
print(tableCheck())
这就是输出
{'topic_title': 'This topic was started: Dec 6 2018, 12:20 PM'},
{'topic_title': 'This topic was started: Nov 19 2018, 10:30 AM'},
{'topic_title': 'This topic was started: Nov 28 2018, 09:16 PM'},
{'topic_title': 'This topic was started: Oct 3 2018, 11:10 AM'},
这就是我试图从中提取数据的单元;我已经试着使用
topic_title = table_tag.find('a', href=True).text
<td class = "row1" valign = "middle" >
<div >
<div style = "float:left" >
<a href = "/topic/4667583" title = "This topic was started: Oct 3 2018,
11:10 AM" >
Xiaomi 70Mai Pro < /a >
</div >
<br >
</div >
</td